Automatically translated.View original post

What is the CSS display?

# Web Site Writing Basics## cssdisplay

CSS display is the feature used to define the display format of each HTML Element, which affects the placement of elements (such as newline or display) and the use of space on a web page, with popular values such as block (newline, full-width space-eating), inline (not newline-up, eat space as needed), inline-block (align in one line, but define width and height), none (hide all elements, do not eat space), as well as values for complex layouts like flex and grid.

Basic features of display:

Display: block;:

Require that the element be rendered like a block, with a new line every time and the full width possible.

The width, height, margin, and padding can be determined.

The inherent block-level element example is < div > or < p >.

Display: inline;:

Require an in-line display element, not a new line, and will only eat as much space as the element needs.

The width and height cannot be determined directly because they do not eat the full width.

The inherent inline-level element example is < span >, < a >, or < img >.

Display: inline-block;:

It's a combination of inline and block.

The elements are lined up on the same line like inline, but width, height, margin, and padding can be defined like block.

Display: none;:

Not only does it disappear from the screen, it will not consume any space on the page, as if it did not exist.

Display for complex layout arrangement:

In addition to the basic features, there are other values used for new layout arrangements:

Display: flex;:

It is used to create a Flexbox layout to place elements in one direction (row or column) flexibly.

Display: grid;:

It is used to create a CSS Grid layout that can control the placement of elements in both row and column axes simultaneously.

The display feature is very important in controlling the appearance and display behavior of elements on a web page, allowing us to create a website with good structure and an impressive user experience (UX).

2025/8/22 Edited to

... Read moreเวลาเจอคำว่า CSS display หลายคนจะนึกถึงแค่ inline กับ block แต่พอทำหน้าเว็บจริง ๆ จะเริ่มสับสนว่า “ทำไมมันไม่ขึ้นบรรทัดใหม่?” “ทำไมกำหนด width ไม่ได้?” หรือ “ซ่อนแล้วมันยังเว้นที่ว่างอยู่ไหม?” อันนี้คือสิ่งที่ฉันใช้เช็กเป็นขั้น ๆ เวลาจัดเลย์เอาต์ 1) เช็กก่อนว่า element ตัวนั้นเป็นอะไรโดยธรรมชาติ - div, p มักเป็น block อยู่แล้ว เลยขึ้นบรรทัดใหม่อัตโนมัติ - span, a มักเป็น inline เลยเรียงต่อกัน และ width/height ไม่ค่อยมีผล ถ้าอยากให้ลิงก์ (<a>) คลิกง่ายขึ้น (พื้นที่ใหญ่ขึ้น) ฉันมักเปลี่ยนเป็น display: inline-block; หรือ block; แล้วค่อยใส่ padding 2) ความต่างที่เจอบ่อย: inline vs inline-block vs block - inline: ไม่ขึ้นบรรทัดใหม่ และขนาดขึ้นกับเนื้อหา (กำหนด width/height ตรง ๆ ไม่ค่อยได้) - inline-block: ไม่ขึ้นบรรทัดใหม่เหมือน inline แต่กำหนด width/height ได้ ใช้ทำปุ่ม เมนู หรือ badge บ่อยมาก - block: ขึ้นบรรทัดใหม่ กินความกว้างเต็มแถว (ตามพื้นที่ที่มี) เหมาะกับ section ต่าง ๆ ของหน้าเว็บ ทริคที่ช่วยชีวิต: ถ้าอยากให้หลายกล่องเรียงกันแต่ยังคุมขนาดเองได้ ให้ลอง inline-block ก่อน (โดยเฉพาะงานง่าย ๆ) 3) display: none; ซ่อนแบบ “หายไปจริง” display: none; คือซ่อนและไม่กินพื้นที่บนหน้าเว็บเลย เหมือนไม่มี element นั้นอยู่ เหมาะกับการซ่อนเมนู/ปุ่มชั่วคราว ถ้าต้องการ “ซ่อนแต่ยังเว้นที่ไว้” (เช่น กันเลย์เอาต์กระโดด) ปกติจะใช้ visibility: hidden; แทน (อันนี้หลายคนชอบสับสน) 4) ตัวอย่าง layout แบบ display: block + inline-block (ง่ายและเร็ว) ฉันมักทำการ์ดสินค้า/บล็อกเล็ก ๆ แบบนี้: - กล่องการ์ดใช้ display: inline-block; - กำหนด width เช่น 200px และ margin ให้มีช่องว่าง เหมาะกับงานที่ไม่ต้อง responsive ซับซ้อนมาก แต่ถ้าจอเล็กแล้วอยากให้จัดเรียงยืดหยุ่น แนะนำไปทาง flex/grid จะคล่องกว่า 5) เริ่มจัดเลย์เอาต์จริงจัง: flex กับ grid ใช้ต่างกันยังไง - display: flex; เหมาะกับการจัดเรียง “แนวเดียว” เป็นหลัก (แถวหรือคอลัมน์) เช่น แถบเมนู ปุ่มเรียงกัน กล่องซ้าย-ขวา และจัดกึ่งกลางแนวตั้ง/แนวนอนได้ง่าย - display: grid; เหมาะกับเลย์เอาต์แบบ “ตาราง” คุมทั้งแถวและคอลัมน์พร้อมกัน เช่น หน้า dashboard, gallery, layout หลายคอลัมน์ที่ต้องกำหนดสัดส่วนชัด ๆ ถ้างานเป็นแถวเดียวฉันจะเริ่มที่ flex ก่อน แต่ถ้าต้องวางเป็นช่อง ๆ หลายมิติ grid จะตรงโจทย์กว่า 6) ใช้ .style.display (JavaScript) เวลาโชว์/ซ่อน ถ้าคุณทำปุ่มกดแล้วให้กล่องแสดง/หาย มักเจอการตั้งค่า element.style.display = 'none'; และตอนโชว์กลับเป็น 'block' หรือ 'flex' ข้อควรระวังจากที่เคยพลาด: ตอนโชว์กลับควรคืนค่าให้ถูกกับเลย์เอาต์เดิม (เช่น เดิมเป็น flex ก็ต้องกลับเป็น flex ไม่งั้น layout จะเพี้ยน) สรุปจำง่ายจากภาพรวม 6 แบบหลัก: none, inline, block, inline-block, flex, grid - จัดตัวอักษร/ลิงก์: เริ่มจาก inline/inline-block - ทำโครงหน้าเว็บเป็นส่วน ๆ: block - ซ่อนแบบไม่เหลือพื้นที่: none - จัดเรียงยืดหยุ่น: flex - ทำตารางเลย์เอาต์: grid

Related posts

A bookstore display features a 'Dark Romance' section with a sign 'My Favorite Color Is Morally Gray.' Prominent books include 'Haunting Adeline' by H.D. Carlton, 'Lights Out,' 'All He'll Ever Be,' and various other dark romance titles.
Dark romance display
#lemon8diarychallenge // second time I’ve seen Haunting Addeline at my B&N #hauntingadeline #hdcarlton #darkromance #barnesandnoble #booktok #bookstageam
Hasina

Hasina

1281 likes

Chrsitmas cookie display part 2
#part2 #DIY #diydollartree #christmasdollartree
Dystracted Designs

Dystracted Designs

7360 likes

DIY trinket display 🫶
This is my fav diy I’ve done so far 😭🙂‍↕️🤩 Such a great yay to display all your mini Funko pops ❤️ #funko #DIY #roomdecor #display #diyroomdecor
Rebecca

Rebecca

343 likes

Updates jewelry display
#jewelry #jewelrydisplay #westernjewelry #turquoisejewelry #turquoiseaddict
♠️Kirsten⚡️🎱

♠️Kirsten⚡️🎱

55 likes

Hanging purse display!
#DIY #pursestorage (I know it’s not the best for the bag straps long term wise but it will do for now 😁)
Love Makyle

Love Makyle

141 likes

The best display solution for F1
#lego #f1 #legodisplay #legoframe #ferrarisf24
Mark’s Magic

Mark’s Magic

197 likes

How I created my vintage garland display
#vintagechristmas #holidaydiy #holidaydecor #garland
Iris.home

Iris.home

55 likes

An iPad on a stand displays a digital record player from the MD Vinyl app, showing Taylor Swift's 'How Did It End?'. The image has a text overlay 'aesthetic iPad display apps you need to try'.
An iPad on a stand displays the MD Vinyl app, showing a digital record player playing Taylor Swift's 'How Did It End?'. A desktop computer with Google Calendar is in the background. Text describes MD Vinyl connecting to music apps.
An iPad on a stand displays the FlipClock app, showing '1 36 PM' in a minimalist digital flip clock style. A desktop computer with Google Calendar is in the background. Text describes FlipClock as an aesthetic clock display with timer features.
My favorite iPad display apps (aesthetic edition)🩷
There's nothing better than having a cozy desk setup while working from home.. and using your iPad as a display definitely helps set the vibe for the day! Two of my favorite iPad display apps ✔️ MD Vinyl ✔️ FlipClock MD Vinyl is 10/10 for aesthetic iPad displays.. I mean isn't this
Allie Marie 🧚🏻

Allie Marie 🧚🏻

6683 likes

a new display for all my race medals! 🏃🏻‍♀️🏅
#running #runningmotivation #runner #runnersoflemon8 #boston
jade marie

jade marie

275 likes

A silver tray holds an assortment of gold and silver necklaces and watches, while a glass bowl overflows with pearl necklaces, showcasing thrifted glassware for jewelry display.
A clear, patterned glass bowl filled with various gold and silver earrings and rings sits on a black shelf, next to a framed picture and a green plant.
A footed glass bowl filled with pearl necklaces is displayed on a white surface, alongside a vintage wooden clock and a stack of books, including 'The Seven Husbands of Evelyn Hugo'.
Jewelry Display with Thrifted Glassware
I recently moved and wanted my bedroom to have more of a dark academia/vintage vibe. I saw a girl on tik tok that used thrifted cake displays to display her jewelry, and that inspired me. I started collecting pieces from my local antique and thrift store and this is what I found! 😊 Enjoy! Le
sophiepeeler

sophiepeeler

175 likes

A clear two-tier display stand organizing a black Nintendo DS Lite console and numerous Nintendo DS game cases. The top tier features a white stand with the DS Lite and game cases, while the bottom tier holds more game cases and a pouch.
A close-up of the white 3D-printed display stand holding a black Nintendo DS Lite and game cases. The stand also features slots for four DS game cartridges, with two cartridges visible.
A wider view of the display stand on a shelf, showcasing its capacity to hold a Nintendo DS Lite console and approximately 15 original DS game cases, with additional games on the bottom tier.
DS Lite Display and Game Organizer (:
Hey friends! Today, I wanted to share this super cool find from Etsy that I purchased last month. It's a display stand and organizer for my ds lite and games! The shop I got it from is called "ZJH3D". I had a very positive experience with both the quality of the item and the shippin
˚ʚ N e o n ɞ˚

˚ʚ N e o n ɞ˚

1295 likes

My Jewelry Display 🎲🎱
#westernjewelry #jewelry #jewelrydisplay #nativejewelry #turquoisejewelry
♠️Kirsten⚡️🎱

♠️Kirsten⚡️🎱

1582 likes

A comprehensive display of western-style turquoise and silver jewelry, featuring necklaces on wooden stands and a bust, along with earrings and pendants on a cowhide-backed rack.
A turquoise blue KOBALT tool chest repurposed as a jewelry display, showcasing numerous silver and turquoise rings on a black velvet organizer on top.
A pink KOBALT tool chest serving as a jewelry display, featuring silver and turquoise bracelets in white dishes, turquoise earrings on a stand, and a ceramic cactus.
My jewelry display🩵
#turquoisejewelry #turquoise #westernjewelry #jewelrydisplay #turquoiseaddict
♠️Kirsten⚡️🎱

♠️Kirsten⚡️🎱

87 likes

Food display idea
food display idea by evet_events #food #cooking #baking #cookingideas #lemon8bookclub
Foodiefan2 🍲😋

Foodiefan2 🍲😋

1550 likes

Book/bible display
If you like what you see, like, comment & follow for more! Thanks for the love in advance! #walmart #walmartfinds #new #bible #books
Shy

Shy

9 likes

Thrift Flip Wire Rack Turned Vintage Plate Display
Turned a simple thrifted wire rack into a charming vintage plate display using champagne gold spray paint and my collection of floral china. 🌸 A cozy farmhouse touch that’s still coming together—just one more plate to go! Would love to know—would you style this in a kitchen or a dining nook?
verenisse311

verenisse311

409 likes

Birthday Floral Display 🌸
Celebrating ALL month! What do you think about this? This chapter I’m choosing happiness and peace 🥰💕 #37 #birthday gift #Lemon8DIY Houston
Stella

Stella

12.5K likes

Bags to use/ display for halloween 🎃🍁🍂
My local SPH doesn’t have much bags anymore being it’s towards the end of the season but these are the remaining cuties i’ve spotted 🥰. some are a bit pricey for me but would love to try and get my hands on any one of these. which one do you like most? or is your favorite out of the bunch?
ᗩᗰᗩᑎᗪᗩ 🪐♡✧˖ °

ᗩᗰᗩᑎᗪᗩ 🪐♡✧˖ °

53 likes

Two keyboards, one light blue and one pink, are displayed on a wooden plate holder on a white shelf. A white bubble candle sits in front. The image highlights the holder as a DIY display solution for keyboards.
Two keyboards, one light blue and one pink, are shown on a wooden display stand on a white desk. The image text indicates these keyboards fit well and the stand is affordable. A pegboard and monitor are in the background.
A white bookcase displays multiple keyboards. A pink keyboard rests on a wooden stand on the top shelf. Two other keyboards are on clear stands on the middle shelf, alongside books. The image emphasizes the display fits perfectly.
DIY Keyboard Display - IKEA Hack
As my keyboard collection continues to grow I struggle to find space to display and organize them. I was in IKEA last week and came across their OSTBIT Plate Holder and thought it would work great as a keyboard holder/display I’m pleasantly surprised with how well it works and priced at only $
doms.cozyspot

doms.cozyspot

224 likes

Display case for McLaren & Senna 🥰
#legodisplay #legotechnic #lego #f1 #mclarenf1
Mark’s Magic

Mark’s Magic

8 likes

Lenox Spice Village Display Ideas
#lenoxvillagecollection #homeaesthetic #homedecor #lenoxspicevillage #vintageaesthetic
cassie

cassie

65 likes

New DT display with new finds!
La Mercerie Pro has dropped a whole beauty display at my Dollar Tree! Makeup, nails, eyes, perfume items, and more. Each only $4! Go check it out before they're gone! #dollartreebeautyfinds #fyp #lemon8beauty #fyplemon8 #shopping @dollartree
GinaBBBudgetBaddie

GinaBBBudgetBaddie

49 likes

An iPhone lock screen displays lavender flowers with text overlay: 'IPHONE HACK - GET YOUR NAME TO SHOW UP ON YOUR SCREEN'. A highlighted area shows 'Princess' with a smiley face and heart emoji, indicating the desired outcome.
An iPhone settings screen shows the search bar with 'Focu' typed, and 'Focus' listed as the top result. Text overlay instructs: 'Go to iphone settings and search Focus for Focus'.
An iPhone screen displays Focus settings. A yellow arrow and text overlay 'Click the plus button' point to a '+' icon in the top right corner, indicating where to add a new Focus.
iPhone Display Hack
How to set up your name on your Lock Screen 👀💕 I hope this helps!! It’s not a must do hack but it looks cute 😂 #iphonetips #iphonehacks #digitalplanning #lemon8challenge
R❤️

R❤️

577 likes

Three lush hanging plants with trailing vines in white pots, illustrating a guide to care, types, and creative displays for hanging plants.
A cozy room filled with various hanging plants and potted plants on a window sill, introducing the benefits and display ideas for hanging plants.
A close-up of a hanging plant with long green vines, highlighting the benefits of hanging plants for air quality, decor, and vertical space utilization.
🪴Hanging houseplants- plant display ideas🪴
🌿With the right care tips and an understanding of available types, you can successfully cultivate thriving hanging plants. 🌿Don’t hesitate to explore new varieties and display techniques to keep your indoor garden fresh and dynamic. 🌿As you embark on your journey with hanging plants, remember tha
Nature Elegance

Nature Elegance

561 likes

A person holds a gaming console in a BMO-inspired stand, displaying a game on its screen. The stand is positioned in front of a computer monitor on a desk, highlighting its use to display the console.
A BMO-inspired stand holds a gaming console on a desk, functioning as a display dock. The screen shows a game, and text indicates it can be used as a dock and mentions a price point.
A BMO-inspired stand with a gaming console is shown on a desk setup. Its adjustable arms allow the console to lean back, making it an adorable and functional display piece for a gaming setup.
Display Your Switch with BMO 🩵
Adventure Time fans listen up! Check out the BMO Nintendo Switch dock. Display your Switch with this adorable guy. You can adjust the arms so lean back so you can have different angles of your Switch. This is such a cute addition to your setup. While it acts like a dock, keep in mind there
CozyGamerVal

CozyGamerVal

38 likes

Coolest Pixel Display
Divoom Pixoo64 Featuring: -Divoom App & Pixel Art Creation -Social Media Tracker & Game KDA -Lighting Decoration & Display Customize -WiFi Connection with More Possibilities -PIXEL ART!!!!! #Unboxing #tech #techfinds #gaming #desksetup #gamingsetup #pixelart #
DeathlyKawaii

DeathlyKawaii

79 likes

Christmas Light Display in Jupiter, Florida
Jupiter's Dazzling Christmas Lights | A Must-Visit Holiday Display #TheSoFloDuo   #SoFloGem   #Florida   #SouthFlorida   #PalmBeaches
Codie N Drew

Codie N Drew

87 likes

The image is a title slide for 'CSS ESSENTIALS Part 11 DISPLAY PROPERTY', introducing the concept of CSS display property as fundamental to layout. It features a question, 'Ever wonder how layout works? It starts with display'.
This image explains 'display: block', showing two 'Block element' boxes stacked vertically, each taking full width. It notes that block elements start on a new line and are used for sections, divs, and paragraphs.
The image illustrates 'display: inline', showing three 'Box' elements ('Box 1', 'Box 2', 'Box 3') sitting next to each other. It explains that inline elements' width fits their content and are used for spans, links, and small text.
CSS Display Property – Control the Layout Flow
Understanding the display property is the foundation of layout in CSS. Whether you're building buttons, sections, or full-page grids — this guide will help you choose the right type. Save and swipe through to level up your CSS skills! #CSSDisplay #LearnCSS #WebDesignTips #FrontendB
Aysha

Aysha

3 likes

See more