search
HomeWeb Front-endHTML TutorialHow to create a collapsible border in HTML?

How to create a collapsible border in HTML?

Aug 31, 2023 pm 12:13 PM
html folding borderCreate a folding borderhtml border folding

How to create a collapsible border in HTML?

We use the border-collapse attribute to create a collapsed border in HTML. border-collapse is a CSS property that sets whether the table border should collapse into a single border or be separated from its own border in HTML.

How to create a collapsible border in HTML?

Border-collapse attribute has four values: separate, collapse, initial, inherit.

Collapse with value

If collapse is passed as the value of the border-collapse property, the table's border will simply collapse to a single border. Following is the syntax for creating a collapsible border in HTML.

border-collapse: collapse;

Example 1

In the example given below, we are trying to create a folding border in HTML -

<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <style>
      table,
      tr,
      th,
      td {
         border: 1px solid black;
         border-collapse: collapse;
      }
   </style>
</head>
<body>
   <h2 id="Tables-in-HTML">Tables in HTML</h2>
   <table style="width: 100%">
   <tr>
      <th>First Name </th>
      <th>Job role</th>
   </tr>
   <tr>
      <td>Tharun</td>
      <td>Content writer</td>
   </tr>
   <tr>
      <td>Akshaj</td>
      <td>Content writer</td>
   </tr>
   </table>
</body>
</html>

The following is the output of the above example program.

Example 2

Let's look at another example, using collapse as the value of the border-collapse property -

<!DOCTYPE html>
<html>
<head>
   <style>
      table {border-collapse: collapse; }
      table, td, th { border: 1px solid blue; }
   </style>
</head>
<body>
   <h1 id="Technologies">Technologies</h1>
   <table>
      <tr>
         <th>IDE</th>
         <th>Database</th>
      </tr>
      <tr>
         <td>NetBeans IDE</td>
         <td>MySQL</td>
      </tr>
   </table>
</body>
</html>

Separate as value

If we create a collapsed border by passing separate as the value of the border-collapse property , the individual cells will be wrapped in separate borders.

border-collapse:separate;

Example 1

In the example given below, we are trying to create a separate collapsible border in HTML.

<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <style>
      table,tr,th,td {
         border:1px solid black;
         border-collapse:separate;
      }
   </style>
</head>
<body>
   <h2 id="Tables-in-HTML">Tables in HTML</h2>
   <table style="width: 100%">
      <tr>
         <th >First Name </th>
         <th>Job role</th>
      </tr>
      <tr>
         <td >Tharun</td>
         <td >Content writer</td>
      </tr>
      <tr>
         <td >Akshaj</td>
         <td >Content writer</td>
      </tr>
      </table>
</body>
</html>

The following is the output of the above example program.

Example 2

Let's look at another example where split is used as the value of the border-collapse property -

<!DOCTYPE html>
<html>
<head>
   <style>
      table {
         border-collapse: separate;
      }
      table,
      td,
      th {
         border: 1px solid blue;
      }
   </style>
</head>
<body>
   <h1 id="Technologies">Technologies</h1>
   <table>
   <tr>
      <th>IDE</th>
      <th>Database</th>
   </tr>
   <tr>
      <td>NetBeans IDE</td>
      <td>MySQL</td>
   </tr>
   </table>
</body>
</html>

Use initial value as value

If initial is passed as the value of the border-collapse property, it will be set to its default value, which is alone. Below is the syntax, which uses the initial properties of the border-collapse attribute in HTML.

border-collapse:initial;

Example

An example is given below, which uses the initial attribute of the border-collapse attribute in HTML.

<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <style>
      table,tr,th,td {
         border:1px solid black;
         border-collapse:initial;
      }
   </style>
</head>
<body>
   <h2 id="Tables-in-HTML">Tables in HTML</h2>
   <table style="width: 100%">
      <tr>
         <th >First Name </th>
         <th>Job role</th>
      </tr>
      <tr>
         <td >Tharun</td>
         <td >Content writer</td>
      </tr>
      <tr>
         <td >Akshaj</td>
         <td >Content writer</td>
      </tr>
   </table>
</body>
</html>

The above is the detailed content of How to create a collapsible border in HTML?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:tutorialspoint. If there is any infringement, please contact admin@php.cn delete
The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function