CSS display none with hidden visibility
# Website Basics # css# displaynone# Visionhidden
The difference between display: none and visibility: hidden is display: none removes all elements from the layout of the page, causing the space previously occupied to disappear, and the user interface (such as a screen reader) cannot see the element at all. While visibility: hidden will hide the element, it will retain the original space of the element on the page, allowing the space to remain intact, and the element can interact with the user (e.g. click) if it is set to do so.
Display: none
Layout Effects:
Remove elements from the layout. No space is used on the page.
Element status:
It's like the element doesn't exist on the page.
Interaction (Interaction):
The element cannot interact with the user, and the screen reader will not access it.
Use case:
Fits hiding all elements completely, such as hiding an inactive menu, or swapping UI components to make the pages rearrange.
Visibility: hidden
Layout Effects:
The elements will hide, but still use the same space.
Element status:
The elements remain but are invisible.
Interaction (Interaction):
Elements can still interact with the user (e.g. click) if they are not turned off with another feature.
Use case:
Fits to temporarily hide content without changing the placement of other elements, or when wanting to hide part of the content but requiring that spaces remain.
Simple summary
Display: none: Gone at all. No space used.
Visibility: hidden: hidden, but use the same space.
นอกจากที่บทความอธิบายไว้เกี่ยวกับ display: none และ visibility: hidden แล้ว การเลือกใช้วิธีใดวิธีหนึ่งควรพิจารณาถึงผลกระทบต่อประสบการณ์ผู้ใช้งานด้วยครับ ในกรณีที่คุณซ่อนไอเท็มแต่ยังต้องการให้ช่องว่างนั้นยังคงอยู่เพื่อความสวยงามหรือโครงสร้างของหน้าเว็บ การใช้ visibility: hidden จะเหมาะกว่า เพราะองค์ประกอบจะยังใช้พื้นที่เดิม แต่ไม่แสดงผล ซึ่งเหมาะกับการซ่อนเนื้อหาชั่วคราว หรือเมนูที่ต้องการเปิดปิดแบบค่อยเป็นค่อยไป แต่หากเป้าหมายคือการลบองค์ประกอบนั้น ๆ ออกอย่างสมบูรณ์ ไม่ให้มีผลต่อการจัดวางและการโต้ตอบเลย ให้ใช้ display: none เพราะจะช่วยให้พื้นที่นั้นถูกตัดออกไป และยังช่วยลดภาระของเบราว์เซอร์ในการเรนเดอร์ส่วนที่ไม่จำเป็น อีกข้อสังเกตที่ผู้ใช้ควรระวังคือ หากใช้ visibility: hidden แล้วองค์ประกอบยังคงโต้ตอบได้ (กรณีตั้งค่า pointer-events ให้เปิดใช้งาน) อาจทำให้ผู้ใช้งานคลิกหรือโต้ตอบกับเนื้อหาที่ไม่เห็นได้ จึงควรตรวจสอบการตั้งค่าใน CSS ด้วยครับ ส่วนประโยชน์จาก OCR ในบทความนี้ยืนยันให้เห็นว่า การเข้าใจความแตกต่างระหว่างสองคำสั่งนี้เป็นเรื่องสำคัญสำหรับนักพัฒนาเว็บทั้งมือใหม่และมืออาชีพ เพื่อช่วยให้หน้าเว็บทำงานได้ตามที่ต้องการทั้งในแง่การแสดงผลและประสิทธิภาพ



































































































