Category: Basic

  • Dimension

    CSS dimension define the size and space occupied by elements on a webpage. The dimension properties like height, width, max-height, max-width, line-height and many more are used to define width, height of HTML elements in every screen sizes. In this tutorial we will learn how to manage dimension and layout of HTML elements in varying screen sizes.

    CSS Setting height and width

    The height and width properties allow you to set specific height and width for your positioned element.

    These properties can hold following values:

    • length: Any unit of length (px, pt, em, in, etc.)
    • percentage (%): A percentage value, which is in percent height/width of the containing block.
    • auto: Browser calculates the height and width of the element. (For example setting height automatically to match aspect ratio of image for the specified width)
    • initial: Sets the value of height and width to its default value.
    • inherit: Inherits the value of height and width from its parent value.

    Example

    <!DOCTYPE html><html><head><style>
    
        div {
            height: 100px;
            width: 80%;
            background-color: rgb(206, 211, 225);
        }
        img{
            height: auto;
            width: 180px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Height and Width Property&lt;/h1&gt;&lt;h2&gt;Length and percentage values&lt;/h2&gt;&lt;div&gt;
        This div element has a height of 50px and a width 
        of 80%.
    &lt;/div&gt;&lt;h2&gt;Auto value&lt;/h2&gt;&lt;img src="/css/images/logo.png"/&gt;&lt;br&gt;
    Height is this image adjusted for width 180px so that 
    aspect ratio is maintained.
    </body></html>

    The padding, margin and border are not included in height and width.

    Set Max-Height and Max-Width

    The max-height and max-width properties are used to set the maximum height and width of an element.

    • max-width: Sets the maximum width an element can be. Prevents an element from exceeding this width, even if the content inside it requires more space.
    • max-height: Sets the maximum height an element can be. Prevents an element from exceeding this height, even if the content inside it requires more space.

    Example

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            width: 90%;
            margin: 0 auto;
            text-align: center;
        }
        
        img{
            max-width: 100%;
            max-height: 400px;
            height: auto;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="container"&gt;&lt;img src="/css/images/logo.png" &gt;&lt;p&gt;
            This image has a maximum width and height set. 
            Resize the browser window to see how the image 
            scales down.
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Set Min-Height and Min-Width

    The min-height and min-width properties are used to set the minimum height and width of an element.

    • min-width: Sets the minimum width an element can be. Ensures that the element doesnt shrink below this width, even if the content is smaller.
    • min-height: Sets the minimum height an element can be. Ensures that the element doesnt shrink below this height, even if the content is smaller.

    Example

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            width: 90%;
            margin: 0 auto;
            text-align: center;
        }
        
        .box {
            min-width: 300px;
            min-height: 200px;
            background-color: #f0f0f0;
            padding: 20px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="container"&gt;&lt;div class="box"&gt;
            This box has a minimum width and height set. 
            Resize the browser window to see how the box 
            does not shrink below the specified dimensions.
        &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Dimension Related Properties

    All the properties related to dimensions are listed in the table below:

    PropertyDescriptionExample
    heightSets the height of an element.Try It
    widthSets the width of an elementTry It
    max-heightSets the maximum height of an elementTry It
    min-heightSets the minimum height of an element.Try It
    max-widthSets maximum width of an element.Try It
    min-widthSets minimum width an element.Try It
  • Outlines

    CSS outline creates lines around the outside of an element’s border, without affecting its size or layout. It means adding an outline won’t affect the element’s size or the positioning of adjacent elements.

    css-outlines

    Types of Outline Properties

    CSS provides following outline properties to style the HTML elements.

    • outline-style: It specifies whether an outline should be solid, dashed line, double line, or one of the other possible values.
    • outline-width: It Specifies the width of an outline.
    • outline-color: It specifies the color of an outline.
    • outline-offset: It specifies the space between an outline and border edge of the element.

    The outline-style Property

    CSS outline-style property specifies the style for the line (solid, dotted, or dashed) that goes around an element.

    Example

    In this example, we have set the outline-style property of each paragraph with different property values.

    <!DOCTYPE html><html><head><style>
    
        p{
            padding: 5px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Outline Style Property&lt;/h1&gt;&lt;p style="outline-style: dotted;"&gt; Dotted outline. &lt;/p&gt;&lt;p style="outline-style: dashed;"&gt; Dashed outline. &lt;/p&gt;&lt;p style="outline-style: solid;"&gt; Solid outline. &lt;/p&gt;&lt;p style="outline-style: double;"&gt; Double outline. &lt;/p&gt;&lt;p style="outline-style: groove;"&gt; Groove outline. &lt;/p&gt;&lt;p style="outline-style: ridge;"&gt; Ridge outline. &lt;/p&gt;&lt;p style="outline-style: inset;"&gt; Inset outline. &lt;/p&gt;&lt;p style="outline-style: outset;"&gt; Outset outline. &lt;/p&gt;&lt;p style="outline-style: none;"&gt; No outline. &lt;/p&gt;&lt;p style="outline-style: hidden;"&gt; Hidden outline. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    The outline-width Property

    CSS outline-width property specifies the width of the outline to be added to the element. Its value should be thin, medium, thick, or length (in pixels, em, etc), just like the border-width attribute.

    Example

    In this example, we have used outline-width property to set the outline width of the paragraphs using values such as thin, medium, thick and by using length(in px).

    <!DOCTYPE html><html><head><style>
    
        p{
            outline-style: solid; 
            padding: 10px;
        }
        p.thin {         
            outline-width: thin;          
        }
        p.medium {
            outline-width: medium;
        }
        p.thick {
            outline-width: thick;
        }
        p.length {
            outline-width: 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p class="thin"&gt; Thin outline width. &lt;/p&gt;&lt;p class="medium"&gt; Medium outline width. &lt;/p&gt;&lt;p class="thick"&gt; Thick outline width. &lt;/p&gt;&lt;p class="length"&gt; Outline Width: 10px. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    The outline-color Property

    To set the color of an outline, the outline-color property is used. If no color is specified for the outline, then the default color i.e. black will be set.

    Example

    In this example, we have used the outline-color property to set the outline color of paragraphs to green and red.

    <!DOCTYPE html><html><head><style>
    
        .name {
                outline-style: dashed; 
                outline-color: red;
                padding: 10px;
                border: 3px solid black;
            }
        .hex {
                outline-style: solid; 
                outline-color: #00ff00;
                padding: 10px;
                border: 3px solid black;
            }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p class="name"&gt; Outline Color: red &lt;/p&gt;&lt;p class="hex"&gt; Outline Color: #00ff00. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    The outline-offset Property

    You can use CSS outline-offset property to set the space between an element and its outline. It is used for creating more visual separation between the element and its outline.

    Example

    In this example, we have used the outline-offset property to create a solid outline of grey color around div having a separation of 10px from the border.

    <!DOCTYPE html><html><head><style>
    
        div {
            margin: 20px;
            border: 2px dotted #000;
            background-color: #08ff90;
            outline: 4px solid #666;
            outline-offset: 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Outline-offset property&lt;/h2&gt;&lt;div&gt; The outline-offset is 10px &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Outline Shorthand Property

    To set the style, width, and color of an outline, we can use the shorthand outline property. The outline-offset property cannot be passed in shorthand property. It needs to be passed separately.

    Syntax

    The syntax for using the CSS outline property is as follows:

    h2{outline: 4px dotted green;outline-offset: 5px;}

    Example

    In this example, we have used the outline property to set the outline of the paragraph and div with different styles, colors, and widths. You can see that the outline-offset property is used separately.

    <!DOCTYPE html><html><head><style>
    
        p {
            outline: solid 4px grey;
            outline-offset: 2px;
            border: 2px solid;
            padding: 5px;
        }
        div {
            /* You can specify in any order */
            outline: 5px dashed darkred;
            outline-offset: 2px;
            border: 2px solid;
            padding: 5px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt; Check the outline of the paragraph !!!&lt;/p&gt;&lt;div&gt; Check the outline of the div !!!&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Using Outline With Focus

    To highlight the elements when they are focused, the outline property is used with the CSS pseudo-class :focus property.

    Example

    In this example, we have used the outline property with the :focus property to set the outline of the input field when it is focused.

    <!DOCTYPE html><html><head><style>
    
        input {
            padding: 10px;
            border: 2px solid #ccc;
            border-radius: 4px;
            outline: none; 
        }
        input:focus {
            outline: 3px solid blue;
            outline-offset: 4px; 
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;input type="text" 
          placeholder="Focus me to see the outline" /&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Outline vs Border

    Following table illustrates the differences between outline and border:

    Outline is a non-rectangular shape that surrounds an element, usually with a solid color.A border is a rectangular shape that is drawn around the content of an element.
    It does not take up any space in the layout and does not affect the size or position of the element.It affects the size and position of the element, as it adds width to the element.
    It is typically used to highlight or emphasize an element, such as when an element is focused or activated.It can be used for various purposes, such as separating elements, creating boxes, and adding visual emphasis.
    It is created using the outline property in CSS.It is created using the border property in CSS.

    Example

    <!DOCTYPE html><html><head><style>
    
        p {
            outline: thick solid red;
            outline-offset: 5px; 
            padding: 10px; 
            border: #009900 inset 10px;
        }
    </style></head><body><p>
        See the difference of outline and border around the p 
        element. The outline is red in color and the border 
        is green.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    List of CSS Outline Properties

    Here we have tabulated all the properties associated with CSS outline.

    PropertyDescriptionExample
    outlineThis example shows all the various values passed to outline as shorthand.Try It
    outline-colorThis example shows all the various values passed to outline-color.Try It
    outline-styleThis example shows all the various values passed to outline-style.Try It
    outline-widthThis example shows all the various values passed to outline-width.Try It
    outline-offsetThis example shows all the various values passed outline-offset.Try It
  • cursor Property

    CSS cursor property determines the appearance of the mouse cursor when hovering over an element to which this property is applied. Its main purpose is to improve usability by visually representing certain functions.

    Syntax

    cursor: value;

    Property Values

    ValueDescription
    autoThe displayed cursor is determined by the user agent based on the current context. This is the default property that the browser uses to define the cursor.
    aliasThe displayed cursor is alias cursor, showing there is need to generate an alias or shortcut.
    all-scrollThe displayed cursor shows that scrolling is done.
    cellThe displayed cursor is cell cursor, showing the option to select the table cell or a group of cells.
    col-resizeThe displayed cursor is coloumn-resize cursor, showing element or column may be subject to horizontal resizing, often represented as arrows pointing left and right, separated by a vertical bar.
    copyThe displayed cursor is copy cursor, showing there is a requirement to create a copy of something.
    crosshairThe displayed cursor is Crosshair cursor, commonly used to indicate the selection of elements in a bitmap.
    defaultThe default cursor, which varies depending on the platform, is usually displayed as an arrow.
    e-resizeThe displayed cursor is south direction resize cursor, showing south side can be moved or shifted.
    ew-sizeThe displayed cursor is east-west resize cursor, showing cursor for bidirectional resizing.
    grabThe displayed cursor is grab cursor, showing that can grab the element and can be dragged to relocate it.
    grabbingThe displayed cursor is grabbing cursor, showing something is being held or pulled to facilitate its movement.
    helpThe displayed cursor is help cursor, showing information for assistance is accessible.
    moveThe displayed cursor is move-cursor, showing something can be relocated.
    n-resizeThe displayed cursor is north direction resize cursor, showing north side can be moved or shifted.
    ne-resizeThe displayed cursor is north-east resize cursor, showing cursor for bidirectional resizing.
    nw-resizeThe displayed cursor is north-west resize cursor, showing cursor for bidirectional resizing.
    ns-resizeThe displayed cursor is north-south resize cursor, showing cursor for bidirectional resizing.
    nesw-resizeThe displayed cursor is north-east south-west resize cursor, showing cursor for bidirectional resizing.
    nwse-resizeThe displayed cursor is north-west south-east resize cursor, showing cursor for bidirectional resizing.
    no-dropThe displayed cursor is no-drop cursor, showing it may not be possible to place the item in its current location.
    not-allowedThe displayed cursor is not-allowed cursor, showing the requested action will not be performed.
    pointerThe displayed cursor is pointer cursor, showing the cursor serves as an indicator pointing to a hyperlink.
    progressThe displayed cursor is progress cursor, showing the program is performing background tasks, allowing the user to maintain interaction with the interface instead of having to wait for its completion.
    row-resizeThe displayed cursor is row-resize cursor, showing element or line may be subject to vertical resizing, usually represented by arrows pointing both upward and downward, separated by a horizontal bar.
    s-resizeThe displayed cursor is south direction resize cursor, showing south side can be moved or shifted.
    se-resizeThe displayed cursor is south-east resize cursor, showing cursor for bidirectional resizing.
    sw-resizeThe displayed cursor is south-west resize cursor, showing cursor for bidirectional resizing.
    textThe displayed cursor is text cursor, showing you can select the text that is normally indicated by an I-shaped cursor.
    URLThe displayed cursor is an image specified by the comma separated urls, a generic cursor must also be provided at the end of urls in case the image can not be used.
    waitThe displayed cursor is cursor, The program is currently occupied, and the user cannot engage with the interface, this state is sometimes represented by an image of an hourglass or a watch.
    w-resizeThe displayed cursor is west direction resize cursor, showing west side can be moved or shifted.
    zoom-inThe displayed cursor is zoom-in, showing an object can be enlarged through zooming.
    zoom-outThe displayed cursor is zoom-out, showing an object can be shrunk through zooming.

    Examples of CSS Cursor Property

    The following examples demostrate the cursor property with different values.

    Demonstration of All Cursors

    The following example shows the demonstration of a number of mentioned cursors, to observe the effect hover over each block.

    Example

    <!DOCTYPE html><html><head><style>
    
      .demo-cursor {
         text-align: center;
         display: inline-block;
         width: 100px;
         height: 100px;
         margin: 10px;
         border: 3px solid #ccc;
         cursor: pointer;
      }
      .demo-cursor:hover {
         background-color: lightgrey;
      }
      .default:hover {
         cursor: default;
      }
      .auto {
         cursor: auto;
      }
      .crosshair {
         cursor: crosshair;
      }
      .pointer {
         cursor: pointer;
      }
      .move {
         cursor: move;
      }
      .text {
         cursor: text;
      }
      .wait {
         cursor: wait;
      }
      .help {
         cursor: help;
      }
      .not-allowed {
         cursor: not-allowed;
      }
      .progress {
         cursor: progress;
      }
      .alias {
         cursor: alias;
      }
      .copy {
         cursor: copy;
      }
      .no-drop {
         cursor: no-drop;
      }
      .e-resize {
         cursor: e-resize;
      }
      .n-resize {
         cursor: n-resize;
      }
      .ne-resize {
         cursor: ne-resize;
      }
      .nw-resize {
         cursor: nw-resize;
      }
      .s-resize {
         cursor: s-resize;
      }
      .se-resize {
         cursor: se-resize;
      }
      .sw-resize {
         cursor: sw-resize;
      }
      .w-resize {
         cursor: w-resize;
      }
      .ew-resize {
         cursor: ew-resize;
      }
      .ns-resize {
         cursor: ns-resize;
      }
      .nesw-resize {
         cursor: nesw-resize;
      }
      .nwse-resize {
         cursor: nwse-resize;
      }
      .col-resize {
         cursor: col-resize;
      }
      .row-resize {
         cursor: row-resize;
      }
      .zoom-in {
         cursor: zoom-in;
      }
      .zoom-out {
         cursor: zoom-out;
      }
      .grab {
         cursor: grab;
      }
      .cell {
         cursor: cell;
      }
      .grabbing {
         cursor: grabbing;
      }
      .all-scroll {
         cursor: all-scroll;
      }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;
      CSS cursor property
    </h2><h3>
      All CSS Cursors, hover the mouse on the blocks.
    </h3><div class="demo-cursor auto"><h3>
         Auto
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor alias"&gt;&lt;h3&gt;
         Alias
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor all-scroll"&gt;&lt;h3&gt;
         All-scroll
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor cell"&gt;&lt;h3&gt;
         cell
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor col-resize"&gt;&lt;h3&gt;
         col-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor copy"&gt;&lt;h3&gt;
         Copy
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor crosshair"&gt;&lt;h3&gt;
         Crosshair
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor default"&gt;&lt;h3&gt;
         Default
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor e-resize"&gt;&lt;h3&gt;
         e-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor ew-resize"&gt;&lt;h3&gt;
         ew-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor grab"&gt;&lt;h3&gt;
         Grab
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor grabbing"&gt;&lt;h3&gt;
         Grabbing
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor help"&gt;&lt;h3&gt;
         Help
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor move"&gt;&lt;h3&gt;
         Move
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor n-resize"&gt;&lt;h3&gt;
         n-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor ne-resize"&gt;&lt;h3&gt;
         ne-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor nw-resize"&gt;&lt;h3&gt;
         nw-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor ns-resize"&gt;&lt;h3&gt;
         ns-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor nesw-resize"&gt;&lt;h3&gt;
         nesw-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor nwse-resize"&gt;&lt;h3&gt;
         nwse-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor no-drop"&gt;&lt;h3&gt;
         No-drop
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor not-allowed"&gt;&lt;h3&gt;
         Not-allowed
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor pointer"&gt;&lt;h3&gt;
         Pointer
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor progress"&gt;&lt;h3&gt;
         Progress
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor row-resize"&gt;&lt;h3&gt;
         row-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor s-resize"&gt;&lt;h3&gt;
         s-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor se-resize"&gt;&lt;h3&gt;
         se-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor sw-resize"&gt;&lt;h3&gt;
         sw-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor text"&gt;&lt;h3&gt;
         Text
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor wait"&gt;&lt;h3&gt;
         Wait
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor w-resize"&gt;&lt;h3&gt;
         w-resize
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor zoom-in"&gt;&lt;h3&gt;
         Zoom-in
      &lt;/h3&gt;&lt;/div&gt;&lt;div class="demo-cursor zoom-out"&gt;&lt;h3&gt;
         Zoom-out
      &lt;/h3&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</code></pre>

    Setting an Image as a Cursor

    An image may also be used as a cursor, the url of the required image has to be mentioned. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .demo-cursor {
         text-align: center;
         display: inline-block;
         background-color: lightgrey;
         width: 100px;
         height: 100px;
         margin: 10px;
         border: 3px solid #ccc;
         cursor: url(/css/images/try-it.jpg), pointer;
      }
    </style></head><body><h2>
      CSS cursor property
    </h2><h3>
      Hover over the block
    </h3><div class="demo-cursor"><h3>
         Image Cursor
      &lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>
  • Paddings

    CSS padding is used to create extra space between the border of the element and its contents. In this chapter we will learn different types of padding and properties associated with it.

    What is CSS Padding?

    In CSS, padding is a property that is used to create additional spacing inside the boundary of an element. The default value for padding is zero. A padding value of zero indicates that content (mostly text content) will start from the border of the element itself.

    CSS Padding Example

    You can try different ways to use to create padding in the below section and you can change the values as well.

    padding: 1em

    padding: 10px 0

    padding: 10px 50px 20px

    padding: 10px 50px 20px 40px

    padding: 30px

    Try Different Padding Options

    Define Padding

    To define any padding on any HTML element, you can use the CSS padding property. This property is shorthand property of ‘padding-top’‘padding-right’‘padding-bottom’, and ‘padding-left’ properties. A single value will generate padding all around the element.

    Syntax

    padding:"value";

    Example

    In this example, we have generated 5px padding surrounding the paragraph element and highlighted the padding area with the light-green background.

    <!DOCTYPE html><html><head><title>CSS Padding</title><style>
    
        div{
            background-color: lightgray;
            border: 1px solid black;
        }
        
        p {
            background-color: white;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Tutorials point&lt;/h1&gt;&lt;h3&gt;CSS Padding&lt;/h3&gt;&lt;div&gt;&lt;p style="padding: 5px;"&gt;
            CSS Padding Applied on Paragraph Element
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Individual Padding Properties

    As we have mentioned earlier the padding is a shorthand property for all Individual sides padding. You can set different padding values for the top, right, bottom, and left sides.

    • padding-top: This property is used to set the top padding of any element.
    • padding-right: This property is used to set the right padding of any element.
    • padding-bottom: This property is used to set the bottom padding of any element.
    • padding-left: This property is used to set the left padding of any element.

    You can check the attached image for more clarity on individual side paddings.

    CSS Padding

    Syntax

    The syntax for the CSS individual padding properties is as follows:

    padding-top:"value";padding-right:"value";padding-bottom:"value";padding-left:"value";

    Example

    In this example, we have created four different elements and generated padding on each element's individual sides with the above-mentioned properties.

    <!DOCTYPE html><html><head><title>CSS Padding</title><style>
    
        div{
            background-color: lightgray;
            border: 1px solid black;
            width: fit-content;
        }
        
        p {
            background-color: lightgreen;
            border: 1px solid black;
            
        }
        span {
            background-color: white;
        }
        .top {
            padding-top: 20px;;
        }
        .bottom {
            padding-bottom: 30px;
        }
        .right {
            padding-right: 30px;
        }
        .left {
            padding-left: 15px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h3&gt;CSS Padding Individual Properties&lt;/h3&gt;&lt;div&gt;&lt;p class="top"&gt;&lt;span&gt;CSS Padding Top Applied on Paragraph Element&lt;/span&gt;&lt;/p&gt;&lt;hr&gt;&lt;p class="right"&gt;&lt;span&gt;CSS Padding Right Applied on Paragraph Element&lt;/span&gt;&lt;/p&gt;&lt;hr&gt;&lt;p class="bottom"&gt;&lt;span&gt;CSS Padding Bottom Applied on Paragraph Element&lt;/span&gt;&lt;/p&gt;&lt;hr&gt;&lt;p class="left"&gt;&lt;span&gt;CSS Padding Left Applied on Paragraph Element&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    All the leftover space on the right side of the element can be confusing to identify the padding, if you try on your own by changing values it will clear the padding concept. Always remember negative values are not allowed for padding in CSS.

    CSS Padding Shorthand Property

    There are four ways to provide value to the CSS padding property all of them are mentioned and described below with the complete example code.

    • Single Values: Here you can provide a single value to the padding property that same value will be applicable on four sides of the the element.
    • Two Values: For two values, the first value(10px) represents the top and bottom padding while the second value(20px) represents the left and right padding. For example - padding: 10px 20px;
    • Three Values: For three values, the first value(10px) represents the top padding, the second value(15px) represents the left and right padding, and the third value(20px) represents the bottom padding. For example - padding: 10px 15px 20px;
    • Four Values: For four values, the first value(5px) represents the top padding, the second value(10px) represents the right padding, the third value(15px) represents the bottom padding, and the fourth value(20px) represents the left padding. For example - padding: 5px 10px 15px 20px;

    Syntax

    The syntax for the padding with single, double, triple, and four values is as follows:

    padding:"value" // Single Value
    padding:"value value" // Two Values
    padding:"value value value" // Three Values
    padding:"value value value value" // Four Values
    

    Example

    In this example, we have set the padding property of paragraph element with single, double, triple and four values.

    <!DOCTYPE html><html><head><title>CSS Padding</title><style>
    
        div{
            background-color: lightgray;
            border: 1px solid black;
        }
        
        p {
            background-color: lightgreen;
            border: 1px solid black;
            padding: 10px;
        }
        .single {
            padding: 20px;
        }
        .double {
            padding: 10px 20px;
        }
        .triple {
            padding: 10px 15px 20px;
        }
        .four {
            padding: 5px 10px 15px 20px;
        }
        
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS padding Property with Single to Four Values&lt;/h2&gt;&lt;div&gt;&lt;p class="single"&gt;&lt;span&gt;Padding property with Single Value.&lt;/span&gt;&lt;/p&gt;&lt;hr/&gt;&lt;p class="double"&gt;&lt;span&gt;Padding property with two Values&lt;/span&gt;&lt;/p&gt;&lt;hr/&gt;&lt;p class="triple"&gt;&lt;span&gt;Padding property with three Values&lt;/span&gt;&lt;/p&gt;&lt;hr/&gt;&lt;p class="four"&gt;&lt;span&gt;Padding property with four Values&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Padding Mix up Units

    CSS does not restrict the usage of multiple units for specifying the padding value while specifying the shorthand property. That means the length value can be passed as pixels along with ems or inches, etc.

    Syntax

    The syntax of padding property value with mix-up units is as follows:

    h2{padding: 20px 4ex .5in 3em;}

    Example

    In this example, we used different units to specify the padding value.

    <!DOCTYPE html><html><head><style>
    
        h2 {
            padding: 20px 4ex .5in 3em; 
            background-color: silver;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;&lt;h2&gt;
            The different length units are passed 
            as padding values to the h2 element.
        &lt;/h2&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Using padding With Percentage Value

    The padding property can be used with a percentage value. The percentages are calculated in relation to the width of the parent element's content area.

    Example

    In this example, we have used a percent value with a padding property to set the padding of the paragraph element.

    <!DOCTYPE html><html><head><style>
    
        div {
            width: 300px;
        }
        p {
            padding: 10%; 
            background-color: silver;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;&lt;p&gt;
            The padding defined for p element is  
            10%, which is calculated as 10% of 
            width of parent element,  which means
            it is 10% of 300px and that is 30px.
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Padding Properties Reference

    You can explore more examples of padding properties by visiting the sub-topics listed in the following table:

    PropertyDescriptionExample
    paddingA shorthand property that is used for setting all the padding properties in one declaration.Try It
    padding-topSets the top padding of an element.Try It
    padding-rightSets the right padding of an element.Try It
    padding-bottomSets the bottom padding of an element.Try It
    padding-leftSets the left padding of an element.Try It


  • Styling Lists

    Lists are useful as they present the information in a structured and organized manner. Lists improve the readability and comprehension of content on a web page. So, if the content is listed, it is easy to follow.

    Lists are commonly used to display items, steps, options, or any other type of related information that should be presented sequentially or in a group.

    This chapter will discuss how to control list type, position, style, etc., using CSS. Before that let us understand what are the type of lists in HTML.

    Table of Contents

    • Types of Lists
    • List Style Type Property
    • List Style Image Property
    • List Style Position Property
    • List Style Shorthand Property
    • Styling Definition List
    • Styling Unordered List
    • List Style Type Reference

    Types of Lists

    Following are types of lists used HTML.

    • Ordered List (<ol>): Used when the items need to be presented in a specific order. Commonly used for procedures, steps, instructions, or any sequence of information where the order matters.
    • Unordered List (<ul>): Used when the order of items doesn’t matter, and you want to present items as a group. Commonly used for lists of features, benefits, options, or any non-sequential information.
    • Definition List (<dl>): Used for terms and their corresponding definitions.

    List Style Type Property

    The CSS list-style-type property is used to change the marker (such as a bullet or number) style for list items in ordered (<ol>) or unordered (<ul>) lists.

    Following example shows some types of list styles.

    Example

    <!DOCTYPE html><html lang="en"><head><style>
    
        /* Unordered List Styles */
        ul.circle {
            list-style-type: circle; /* Circle bullets */
        }
        ul.square {
            list-style-type: square; /* Square bullets */
        }
        ul.none {
            list-style-type: none; /* No bullets */
        }
        /* Ordered List Styles */
        ol.decimal {
            list-style-type: decimal; /* Default decimal numbers */
        }
        ol.upper-roman {
            list-style-type: upper-roman; /* Uppercase Roman numerals */
        }
        ol.lower-alpha {
            list-style-type: lower-alpha; /* Lowercase alphabetic characters */
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Unordered Lists&lt;/h2&gt;&lt;ul class="circle"&gt;&lt;li&gt;Circle bullet 1&lt;/li&gt;&lt;li&gt;Circle bullet 2&lt;/li&gt;&lt;li&gt;Circle bullet 3&lt;/li&gt;&lt;/ul&gt;&lt;ul class="square"&gt;&lt;li&gt;Square bullet 1&lt;/li&gt;&lt;li&gt;Square bullet 2&lt;/li&gt;&lt;li&gt;Square bullet 3&lt;/li&gt;&lt;/ul&gt;&lt;ul class="none"&gt;&lt;li&gt;No bullet &lt;/li&gt;&lt;li&gt;No bullet &lt;/li&gt;&lt;li&gt;No bullet &lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Ordered Lists&lt;/h2&gt;&lt;ol class="decimal"&gt;&lt;li&gt;Decimal number &lt;/li&gt;&lt;li&gt;Decimal number &lt;/li&gt;&lt;li&gt;Decimal number &lt;/li&gt;&lt;/ol&gt;&lt;ol class="upper-roman"&gt;&lt;li&gt;Roman numeral &lt;/li&gt;&lt;li&gt;Roman numeral &lt;/li&gt;&lt;li&gt;Roman numeral &lt;/li&gt;&lt;/ol&gt;&lt;ol class="lower-alpha"&gt;&lt;li&gt;Letter &lt;/li&gt;&lt;li&gt;Letter &lt;/li&gt;&lt;li&gt;Letter &lt;/li&gt;&lt;/ol&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    List Style Image Property

    The list-style-image property can be used to to specify an image/icon as an item list marker.

    You can use your own bullet style. If no image is found, then default bullets are returned.

    Example

    <!DOCTYPE html><html><head><style>
    
        ul { 
            list-style-image: url('/css/images/smiley.png');
        }
        ol{
            list-style-type: upper-roman;
            list-style-image: url('/css/images/smiley');      
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;ul&gt;&lt;li&gt; This is unordered list &lt;/li&gt;&lt;li&gt; We made custom marker for this &lt;/li&gt;&lt;/ul&gt;&lt;ol&gt;&lt;li&gt; Incorrect URL given for ol style &lt;/li&gt;&lt;li&gt; No custom image will be used.&lt;/li&gt;&lt;li&gt; Specified style type will be used. &lt;/li&gt;&lt;/ol&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    It is advisable to provide an alternative for an image as list marker, so that in case of image not getting loaded or gets corrupted, the user is having a fallback option.

    List Style Position Property

    The list-style-position property indicates whether the marker should appear inside or outside of the box containing the bullet points. It can have one of the following values.

    • list-style-position: inside If the text goes onto a second line, the text will wrap underneath the marker. It will also have proper indentation.
    • list-style-position: outside If the text goes onto a second line, the text will be aligned with the start of the first line (to the right of the bullet).
    • list-style-position: inherit Inherits the property of the parent list in the case of nested lists.

    Example

    <!DOCTYPE html><html><head><style>
    
        body{
            padding: 10px;
        }
        ul {
            padding: 0;
            border-left: solid 2px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;ul style = "list-style-position:outside;"&gt;&lt;li&gt;
          The list style position property is outside. In this 
          case when text overflows to the next line, the marker 
          will lay outside the text area of list. 
      &lt;/li&gt;&lt;li&gt; Check out yourselves. &lt;/li&gt;&lt;/ul&gt;&lt;ul style = "list-style-position:inside;"&gt;&lt;li&gt;
          The list style position property is inside. In this 
          case when text overflows to the next line, the marker 
          will lay inside the text area of list. 
      &lt;/li&gt;&lt;li&gt; Check out yourselves. &lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    List Style Shorthand Property

    The list-style property allows you to specify all the three list properties in a single declaration.

    ul{list-style:url() | Marker Type |  Marker Position;}

    You can follow any order of the values for the list-style property. If any of the value(s) is missing, it will be filled by the default value for the same. But there has to be minimum one value passed.

    Example

    <!DOCTYPE html><html><head><style>
    
        ul{
           list-style: url('/css/images/smiley.png')  circle outside;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;List style shorthand&lt;/h2&gt;&lt;ul&gt;&lt;li&gt; Item 1&lt;/li&gt;&lt;li&gt; Item 2&lt;/li&gt;&lt;li&gt; Item 3&lt;/li&gt;&lt;li&gt; Item 4&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Styling Unordered List

    Following example shows how to style a unordered list in CSS by adding background colors, hover effect and other CSS properties.

    Example

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            font-family: Arial, sans-serif;
            background-color: #f9f9f9;
            color: #333;
            margin: 20px;
            display: flex;
            justify-content: space-around;
        }
        h2 {
            color: #2c3e50;
        }
        .styled-list {
            list-style-type: none; 
            padding: 0;
            margin: 20px 0;
        }
        .styled-list li {
            background-color: #e3f2fd; 
            margin: 5px 0; 
            padding: 10px;
            border-radius: 5px;
            transition: background-color 0.3s ease;
            display: flex;
            align-items: center;
        }
        .styled-list li::before {
            content: ""; 
            color: #3498db; 
            font-weight: bold;
            margin-right: 10px;
        }
        .styled-list ol li::before {
            content: counter(list-item) ". "; 
            font-weight: bold;
            color: #3498db;
        }
        .styled-list li:hover {
            background-color: #bbdefb; 
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="container"&gt;&lt;div class="ul"&gt;&lt;h2&gt;Unordered List&lt;/h2&gt;&lt;ul class="styled-list"&gt;&lt;li&gt;First item&lt;/li&gt;&lt;li&gt;Second item&lt;/li&gt;&lt;li&gt;Third item&lt;/li&gt;&lt;li&gt;Fourth item&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Styling Definition List

    The following example shows how to style a definition list in CSS by adding background colors, hover effects, and other CSS properties.

    Example

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            font-family: Arial, sans-serif;
            background-color: #f9f9f9;
            color: #333;
            margin: 20px;
            display: flex;
            justify-content: space-around;
        }
        h2 {
            color: #2c3e50;
        }
        .styled-dl {
            margin: 20px 0;
            padding: 0;
        }
        .styled-dl dt {
            background-color: #e3f2fd;
            margin: 5px 0;
            padding: 10px;
            border-radius: 5px;
            font-weight: bold;
            transition: background-color 0.3s ease;
        }
        .styled-dl dd {
            margin-left: 20px;
            margin-bottom: 10px;
            padding-left: 10px;
            border-left: 3px solid #3498db;
            color: #555;
            background-color: #f1f8e9;
            border-radius: 5px;
            transition: background-color 0.3s ease;
        }
        .styled-dl dt:hover,
        .styled-dl dd:hover {
            background-color: #bbdefb;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="container"&gt;&lt;div class="dl"&gt;&lt;h2&gt;Definition List&lt;/h2&gt;&lt;dl class="styled-dl"&gt;&lt;dt&gt;HTML&lt;/dt&gt;&lt;dd&gt; 
                    A standard markup language for creating web 
                    pages.
                &lt;/dd&gt;&lt;dt&gt;CSS&lt;/dt&gt;&lt;dd&gt;
                    A style sheet language used for describing the 
                    presentation of a document.
                &lt;/dd&gt;&lt;dt&gt;JavaScript&lt;/dt&gt;&lt;dd&gt;
                    A programming language that enables interactive 
                    web pages.
                &lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    List Style Type Reference

    Following table lists possible values that can be used for property list-style-type:

    ValueDescriptionExample
    noneNo any marker will be displayed.NA
    disc (default)A filled-in circle
    circleAn empty circle
    squareA filled-in square
    decimalNumber1, 2, 3, 4, 5, ...
    decimal-leading-zero0 before the number01, 02, 03, 04, 05, ...
    lower-alphaLowercase alphanumeric charactersa, b, c, d, e, ...
    upper-alphaUppercase alphanumeric charactersA, B, C, D, E, ...
    lower-romanLowercase Roman numeralsi, ii, iii, iv, v, ...
    upper-romanUppercase Roman numeralsI, II, III, IV, V, ...
    lower-greekThe marker is lower-greekalpha, beta, gamma, ...
    lower-latinThe marker is lower-latina, b, c, d, e, ...
    upper-latinThe marker is upper-latinA, B, C, D, E, ...
    hebrewThe marker is traditional Hebrew numbering 
    armenianThe marker is traditional Armenian numbering 
    georgianThe marker is traditional Georgian numbering 
    cjk-ideographicThe marker is plain ideographic numbers 
    hiraganaThe marker is Japanese numbering - hiraganaa, i, u, e, o, ka, ki
    katakanaThe marker is Japanese numbering - katakanaA, I, U, E, O, KA, KI
    hiragana-irohaThe marker is Japanese numbering (hiragana-iroha)i, ro, ha, ni, ho, he, to
    katakana-irohaThe marker is Japanese numbering (katakana-iroha)I, RO, HA, NI, HO, HE, TO
  • Margins

    CSS margins are used to create space around the outer part of an element. In this tutorial, we will learn how to add different types of margins to HTML elements and the properties associated with it.

    What is CSS Margin?

    • A Margin in CSS makes the layout visually appealing by adding extra space between elements.
    • You can set the margin for individual sides using properties margin-bottommargin-topmargin-left and margin-right.
    • Negative Margin: A margin with a negative value indicates the elements overlap with each other.

    CSS Margins Example

    You can try different ways to use to create margins in the below section and you can change the values as well.

    margin: 1em

    margin: 10px 0

    margin: 10px 50px 20px

    margin: 10px 50px 20px 40px

    margin: 30px

    Try Different Margin Options

    Define Margin

    To define any margin on any HTML element you can use the CSS margin property. This property is a shorthand property of the ‘margin-top’‘margin-right’‘margin-bottom’, and ‘margin-left’ properties. A single value will generate a margin all around the element.

    Syntax

    margin:"value";

    Example

    As you can see in this below example we have made a 10px and 20px margin surrounding the paragraph element and highlighted the margin area with light-green background.

    <!DOCTYPE html><html><head><title>CSS Margin</title><style>
    
        div{
            background-color: #04af2f;
            border: 1px solid black;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS Margin&lt;/h2&gt;&lt;div&gt;&lt;div style="margin: 20px; background: white;"&gt;
            CSS Margin 20px all sides
        &lt;/div&gt;&lt;hr color="red"&gt;&lt;div style="margin: 10px; background: white;"&gt;
            CSS Margin 10px all sides
        &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Individual Margin Properties

    As we have mentioned earlier the margin is a shorthand property for all Individual sides margin. You can set different margin values for the top, right, bottom and, left sides.

    • margin-top: This property is used to set the top margin of any element.
    • margin-right: This property is used to set the right margin of any element.
    • margin-bottom: This property is used to set the bottom margin of any element.
    • margin-left: This property is used to set the left margin of any element.

    You can check the attached image for more clarity on individual side margins.

    CSS Margin

    Syntax

    The syntax for the CSS individual margin properties is as follows:

    margin-top:"value";margin-right:"value";margin-bottom:"value";margin-left:"value";

    Example

    In this example, we have created four different elements and generated a margin on each element's individual sides with the above-mentioned properties.

    <!DOCTYPE html><html><head><title>CSS Margin</title><style>
    
        div{
            background-color: lightgray;
            border: 1px solid black;
            width: fit-content;
        }
        
        p {
            border: 1px solid black;
            
        }
        span {
            background-color: white;
        }
        .top {
            margin-top: 20px;;
        }
        .bottom {
            margin-bottom: 30px;
        }
        .right {
            margin-right: 30px;
        }
        .left {
            margin-left: 15px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h3&gt;CSS Margin Individual Properties&lt;/h3&gt;&lt;div&gt;&lt;p class="top"&gt;&lt;span&gt;CSS Margin Top Applied on Paragraph Element&lt;/span&gt;&lt;/p&gt;&lt;hr&gt;&lt;p class="right"&gt;&lt;span&gt;CSS Margin Right Applied on Paragraph Element&lt;/span&gt;&lt;/p&gt;&lt;hr&gt;&lt;p class="bottom"&gt;&lt;span&gt;CSS Margin Bottom Applied on Paragraph Element&lt;/span&gt;&lt;/p&gt;&lt;hr&gt;&lt;p class="left"&gt;&lt;span&gt;CSS Margin Left Applied on Paragraph Element&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Margin Shorthand Property

    There are four ways to provide value to the CSS margin property all of them are mentioned and described below with the complete example code.

    • Single Value: Here you can provide a single value to the margin property that same value will be applicable on four sides of the the element.
    • Two Values: For two values, the first value(10px) represents the top and bottom margin while the second value(20px) represents the left and right margin. For example − margin: 10px 20px;
    • Three Values: For three values, the first value(10px) represents the top margin, the second value(15px) represents the left and right margin, and the third value(20px) represents the bottom margin. For example − margin: 10px 15px 20px;
    • Four Values: For four values, the first value(5px) represents the top margin, the second value(10px) represents the right margin, the third value(15px) represents the bottom margin, and the fourth value(20px) represents the left margin. For example − margin: 5px 10px 15px 20px;

    Syntax

    The syntax for the margin with single, double, triple, and four values is as follows:

    margin:"value" // Single Value
    margin:"value value" // Two Values
    margin:"value value value" // Three Values
    margin:"value value value value" // Four Values
    

    Example

    In this example, we have set the margin property of paragraph element with single, double, triple and four values.

    <!DOCTYPE html><html><head><title>CSS Margin</title><style>
    
        div{
            background-color: lightgray;
            border: 1px solid black;
        }
        
        p {
            background-color: lightgreen;
            border: 1px solid black;
            padding: 10px;
        }
        .single {
            margin: 20px;
        }
        .double {
            margin: 10px 20px;
        }
        .triple {
            margin: 10px 15px 20px;
        }
        .four {
            margin: 5px 10px 15px 20px;
        }
        
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS margin Property with Single to Four Values&lt;/h2&gt;&lt;div&gt;&lt;p class="single"&gt;&lt;span&gt;Margin property with Single Value.&lt;/span&gt;&lt;/p&gt;&lt;hr/&gt;&lt;p class="double"&gt;&lt;span&gt;Margin property with two Values&lt;/span&gt;&lt;/p&gt;&lt;hr/&gt;&lt;p class="triple"&gt;&lt;span&gt;Margin property with three Values&lt;/span&gt;&lt;/p&gt;&lt;hr/&gt;&lt;p class="four"&gt;&lt;span&gt;Margin property with four Values&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Margin Mix up Units

    CSS does not restrict the usage of multiple units for specifying the margin value while specifying the shorthand property. That means the length value can be passed as pixels along with ems or inches, etc.

    Syntax

    The syntax of margin property value with mix-up units is as follows:

    h2{margin: 20px 4ex .5in 3em;}

    Example

    In this example, we used different units to specify the margin value.

    <!DOCTYPE html><html><head><style>
    
        div{
            border: 2px solid;
        }
        h2 {
            margin: 20px 4ex .5in 3em; 
            background-color: silver;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;&lt;h2&gt;
            The different length units are passed 
            as margin values to the h2 element.
        &lt;/h2&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Using margin With Percentage Value

    The margin property can be used with a percentage value. The percentages are calculated in relation to the width of the parent element's content area.

    Example

    In this example, we have used a percent value with margin property to set the margin of the paragraph element.

    <!DOCTYPE html><html><head><style>
    
        div {
            width: 300px;
            border: 2px solid;
        }
        p {
            margin: 10%; 
            background-color: silver;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;&lt;p&gt;
            The margin defined for p element is    
            10%which is calculated as 10% of width
            of parent element(div), which means
            it is 10% of 300px and that is 30px.
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Centering Elements with CSS Margin

    To center an element using CSS margin property, we use auto value with margin property.

    Example

    In this example, we have centered a div element using margin:auto value.

    <!DOCTYPE html><html><head><style>
    
        div {
            width: 200px;
            margin: auto;
            background-color: lightgray;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS margin:auto Property&lt;/h2&gt;&lt;div&gt;
        A div element centered using margin: auto;
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Margin Properties Reference

    You can explore more examples of margin properties by visiting the sub-topics listed in the following table:

    PropertyDescriptionExample
    marginA shorthand property that is used for setting all the margin properties in one declaration.Try It
    margin-topSets the top margin of an element.Try It
    margin-rightSets the right margin of an element.Try It
    margin-bottomSets the bottom margin of an element.Try It
    margin-leftSets the left margin of an element.Try It

  • border inline Property

    CSS border-inline is a shorthand property that sets the values for different logical inline border attributes, border-inline-width, border-inline-style and border-inline-color in one single declaration. The border-style is required. Default values of color and width will be used if not specified. The property is affected by writing mode, text-orientation and direction.

    Syntax

    border-inline: border-inline-width border-inline-style border-inline-color | initial | inherit;

    Property Values

    ValueDescription
    border-inline-widthIt specifies the width of element borders in inline direction. Default value is medium.
    border-inline-styleIt specifies the style of element borders in inline direction. Default value is none.
    border-inline-colorIt specifies the color of element borders in inline direction. Default value is color of the text.
    initialIt sets the property to its default value.
    inheritIt inherits the property from the parent element.

    Examples of CSS Border Inline Property

    The following examples explain the border-inline porperty with different values.

    Defining All Values of Border Inline Property

    To define the values of border-inline-widthborder-inline-style and border-inline-color in one single declaration, we use the border-inline property.The following example shows how this is done.

    Example

    <!DOCTYPE html><html><head><style>
    
      .container {
         background-color: lightgrey;
         width: 100vh;
         height: 400px;
         display: block;
         justify-content: center;
         padding: 25px;
         text-align: center;
         font-weight:bold;
      }
      .borders {
         border: 1px solid black;
         padding: 20px;
      }
      .border1 {
         border-inline: 4px solid red;
      }
      .border2 {
         border-inline: 6px dashed blue;
      }
      .border3 {
         border-inline: 8px dotted yellow;
      }
      .border4 {
         border-inline: 8px double brown;
      }
    </style></head><body><h2>
      CSS border-inline property
    </h2><div class="container"><p class="borders border1">
         This has border-inline property with 
         4px width solid style and red color
      &lt;/p&gt;&lt;p class="borders border2"&gt;
         This has border-inline property with 
         6px width dashed style and blue color
      &lt;/p&gt;&lt;p class="borders border3"&gt;
         This has border-inline property with 
         8px width dotted style and yellow color
      &lt;/p&gt;&lt;p class="borders border4 "&gt;
         This has border-inline property with 
         8px width double style and brown color
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Constituent Properties of Border Inline Property

    The border-inline property is composed of properties border-inline-widthborder-inline-style and border-inline-color. The following example shows how these individual properties combine to show the border-inline effect.

    Example

    <!DOCTYPE html><html><head><style>
    
      .container {
         background-color: lightgreen;
         width: 100vh;
         height: 200px;
         display: block;
         justify-content: center;
         padding: 25px;
         text-align: center;
         font-weight: bold;
      }
      .borders {
         border: 1px solid black;
         padding: 20px;
      }
      .border1 {
         border-inline-width: 4px;
         border-inline-style: solid;
         border-inline-color: red;
      }
      .border2 {
         border-inline-width: 6px;
         border-inline-style: dashed;
         border-inline-color: blue;
      }
    </style></head><body><h2>
      CSS border-inline property
    </h2><div class="container"><p class="borders border1">
      This has border-inline-width:4px, 
      border-inline-style:solid, 
      border-inline-color:red
    </p><p class="borders border2">
      This has border-inline-width:6px, 
      border-inline-style:dashed, 
      border-inline-color:blue
    </p></div></body></html>

    Border Inline Property with Writing Mode

    The border-inline property is affected by the writing mode which decides the direction of the inline borders. In vertical writing mode, it affects the top and bottom borders while in horizontal writing mode, it affects the left and right borders. These are shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .container {
         display: block;
         justify-content: center;
         padding: 25px;
         text-align: center;
         font-weight: bold;
      }
      .borders {
         border: 1px solid black;
         padding: 20px;
      }
      .border1 {
         border-inline: 4px solid red;
         writing-mode: horizontal-rl;
      }
      .border2 {
         border-inline: 6px dashed blue;
         writing-mode: vertical-rl;
      }
    </style></head><body><h2>
      CSS border-inline property
    </h2><div class="container"><p class="borders border1">
      This has border-inline 4px width, 
      solid style, red color and 
      horizontal writing mode.
    </p><p class="borders border2">
      This has border-inline 6px width,
      dashed style, blue color and 
      vertical writing mode.
    </p></div></body></html>
  • border block Property

    CSS border-block property is a shorthand property for assigning values to border-block-color, border-block-style and border-block-width in one go. The border-block-style is required parameter. If other parameters are not mentioned then default values will be used. This property depends on the direction of the block which is determined by the writing mode.

    Syntax

    border-block: border-block-width border-block-style border-block-color | initial | inherit;

    Property Values

    ValueDescription
    border-block-widthIt specifies the width of the border in the block direction. Default is medium.
    border-block-styleIt specifies the style of the border in the block direction. Default is none.
    border-block-colorIt specifies the color of the border in the block direction. Default is text’s color.
    initialThis sets the property to its default value.
    inheritThis inherits the property from the parent element.

    Examples of CSS Border Block Property

    The following examples explain the border-block property with different values.

    Setting the Width of Border

    To set the width of the border, we use the border-block-width component of the border-block property. In the following example, we have used ‘thick’ and 10px width for border-block-width property.

    Example

    <!DOCTYPE html><html><head><style>
    
        #width1 {
            padding: 30px;
            border-block-style: solid;
            border-block-width: thick;
        }
        #width2 {
            padding: 30px;
            border-block-style: solid;
            border-block-width: 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS border-block property&lt;/h2&gt;&lt;p id="width1"&gt;
        This first example shows the width property 
        of the border-block with thick value.
    &lt;/p&gt;&lt;p id="width2"&gt;
        This second example shows the width property 
        of the border-block with 10px value.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting the Style of Border

    To set the style of the border, we use the border-block-style component of the border-block property. In the following example, we have used 'solid' and 'dashed' styles for border-block-style property.

    Example

    <!DOCTYPE html><html><head><style>
    
        #style1 {
            padding: 30px;
            border-block-style: solid;
        }
        #style2 {
            padding: 30px;
            border-block-style: dashed;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS border-block property&lt;/h2&gt;&lt;p id="style1"&gt;
        This first example shows the style property 
        of the border-block with solid value.
    &lt;/p&gt;&lt;p id="style2"&gt;
        This second example shows the style property 
        of the border-block with dashed value.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting the Color of Border

    To set the color of the border, we use the border-block-color component of the border-block property. In the following example, we have used 'red' and 'blue' colors for border-block-color property.

    Example

    <!DOCTYPE html><html><head><style>
    
        #color1 {
            padding: 30px;
            border-block-style: solid;
            border-block-color:red;
        }
        #color2 {
            padding: 30px;
            border-block-style: solid;
            border-block-color:blue;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS border-block property&lt;/h2&gt;&lt;p id="color1"&gt;
        This first example shows the color property 
        of the border-block with red value.
    &lt;/p&gt;&lt;p id="color2"&gt;
        This second example shows the color property 
        of the border-block with blue value.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting all Values at Once

    To set the values of width, style and color at once, we can simply use the border-block property by providing all the values at once. In the following example, the width has been taken as 5px, style as dashed and color as green.

    Example

    <!DOCTYPE html><html><head><style>
    
        #block {
            padding: 30px;
            border-block: 5px dashed green;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS border-block property&lt;/h2&gt;&lt;p id="block"&gt;
        This example shows the border-block property 
        defining all values at once.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting Border Block with Writing Mode

    The writing-mode in the context of border-block influences the direction of the border. By default, the border appears horizontally, however by changing the writing mode, the border's direction can be changed

    • Horizontal-tb: border appears horizontally.
    • Vertical-lb: border appears vertically.

    These are shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
        #horizontal {
            inline-size: 200px;
            padding: 10px;
            writing-mode: horizontal-tb;
            border-block: 5px dashed red;
        }
        #vertical {
            inline-size: 200px;
            padding: 10px;
            writing-mode: vertical-rl;
            border-block: 5px dashed green;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS border-block property&lt;/h2&gt;&lt;div&gt;&lt;p id="horizontal"&gt;This example shows the
        horizontal boder.&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;p id="vertical"&gt; This example shows the 
        vertical border.&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • Borders

    The border property creates a border around an HTML element, such as a div, image, or text. You can customize the border by changing the border stylewidthradius, and color for each side of the element. Borders help in improving the readability of the content as it provide separation of content and is also useful for highlighting important sections of the web page.

    CSS Borders Example

    You can try different ways to set the border in the below section and you can change the values as well.

    CSS Border Interactive Example

    Interactive example for CSS BordersBorder Width:  pxBorder Radius:  pxBorder Style:                      Solid                     Dashed                     Dotted                     Double                     Groove                     Ridge                     Inset                     Outset                 Border Color: 

    CSS Border Shorthand Property

    You can use the shorthand CSS border property to specify the border width, style, and color.

    Syntax

    The syntax for the border shorthand property is as follows:

    border: border-width border-style border-color | initial | inherit;

    Example

    In this example, we have used the CSS border property to set the border of a div and paragraph element.

    <html><head><style>
    
        p {
            border: solid 4px grey;
            padding: 10px;
        }
        div{
            border: darkred solid 5px;
            padding: 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt; Check the borders of paragraph !!!&lt;/p&gt;&lt;div&gt; Check the borders of div !!!&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Types of Border Properties

    In CSS, we can style the following border properties:

    • border-style: It specifies whether a border should be solid, dashed line, double line, or one of the other possible values.
    • border-width: It specifies the width of a border.
    • border-color: It specifies the color of a border.

    CSS border-style Property

    To specify the type of border style for an element, the border-style property is used. You can specify border style as solid, dashed, or dotted. Check out the output of the following example for all the types of border styles.

    Example

    In this example, we have used the border-style property to set the different border styles for each paragraph element.

    <!DOCTYPE html><html><head><style>
    
        .none {
            border-style: none;
        }
        .hidden {
            border-style: hidden;
        }
        .dotted {
            border-style: dotted;
        }
        .dashed {
            border-style: dashed;
        }
        .solid {
            border-style: solid;
        }
        .double {
            border-style: double;
        }
        .groove {
            border-style: groove;
        }
        .ridge {
            border-style: ridge;
        }
        .inset {
            border-style: inset;
        }
        .outset {
            border-style: outset;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Border Style Property&lt;/h1&gt;&lt;p class="none"&gt; No border.&lt;/p&gt;&lt;p class="hidden"&gt; Hidden border.&lt;/p&gt;&lt;p class="dotted"&gt; Dotted border.&lt;/p&gt;&lt;p class="dashed"&gt; Dashed border.&lt;/p&gt;&lt;p class="solid"&gt; Solid border.&lt;/p&gt;&lt;p class="double"&gt; Double border.&lt;/p&gt;&lt;p class="groove"&gt; Groove border.&lt;/p&gt;&lt;p class="ridge"&gt; Ridge border.&lt;/p&gt;&lt;p class="inset"&gt; Inset border.&lt;/p&gt;&lt;p class="outset"&gt; Outset border.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Border Style For Individual Sides

    You can specify different border styles for each side of the element. To set the border-style property for the individual sides of the element, we use the following CSS properties:

    • border-top-style: It sets the style of an element's top border.
    • border-bottom-style: It sets the style of an element's bottom border.
    • border-left-style: It sets the style of an element's left border.
    • border-right-style: It sets the style of an element's right border.

    Example

    In this example, we have used the CSS border-style property for individual sides to set the different border styles for each side of a paragraph element.

    <html><head><style>
    
        p {
            border-top-style: dotted; 
            border-right-style: solid; 
            border-bottom-style: dashed; 
            border-left-style: double;
            padding: 2em;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Border Style Individual Side&lt;/h2&gt;&lt;p&gt;Different border styles on all sides.&lt;/p&gt;&lt;/body&gt;&lt;html&gt;</pre>

    CSS border-width Property

    The border-width is used to specify the thickness of a border around an element. It can have values like thin, medium, thick, or any length (in px, or em ). Let us look at an example of this.

    Example

    In this example, we have used the CSS border-width property to set the different border widths for each paragraph element.

    <html><head><style>
    
        p.thin {
            border-style: solid; 
            border-width: thin;
            padding: 10px;
        }
        p.medium {
            border-style: solid; 
            border-width: medium;
            padding: 10px;
        }
        p.thick {
            border-style: solid; 
            border-width: thick;
            padding: 10px;
        }
        p.length {
            border-style: solid; 
            border-width: 10px;
            padding: 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p class="thin"&gt;Thin width.&lt;/p&gt;&lt;p class="medium"&gt;Medium width.&lt;/p&gt;&lt;p class="thick"&gt;Thick width.&lt;/p&gt;&lt;p class="length"&gt;Border Width: 10px.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Declare border-style property before declaring border-width property, else the border effect will not be seen.

    Border Width For Individual Sides

    You can specify different border widths for each side of an element. To set the border-width property for individual sides, use the following CSS properties:

    • border-top-width: Sets the width of the top border.
    • border-bottom-width: Sets the width of the bottom border.
    • border-left-width: Sets the width of the left border.
    • border-right-width: Sets the width of the right border.

    Example

    In this example, we have used the CSS border-width property for individual sides to set different border widths for each side of a paragraph element.

    <html><head><style>
    
        p {
            border-style: solid;
            border-top-width: thin; 
            border-right-width: thick; 
            border-bottom-width: medium; 
            border-left-width: 10px;
            padding: 2em;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Border Width Individual Sides&lt;/h2&gt;&lt;p&gt;Different border widths on all sides.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS border-color Property

    The border-color is used to set the color of the border. If no color is specified for the border, the default value is currentColor i.e. the foreground color.

    Example

    In this example, we have used the CSS border-color property to set the border colors of paragraph elements using the color name and hex value.

    <html><head><style>
    
        .name {
                border-style: dashed; 
                border-color: red;
                padding: 10px;
            }
        .hex {
                border-style: solid; 
                border-color: #00ff00;
                padding: 10px;
            }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p class="name"&gt;Border Color: red&lt;/p&gt;&lt;p class="hex"&gt;Border Color: #00ff00.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Declare border-style property before declaring border-color property, else the border effect will not be seen.

    Border Color For Individual Sides

    You can specify different border colors for each side of an element. To set the border-color property for individual sides, use the following CSS properties:

    • border-top-color: Sets the color of the top border.
    • border-bottom-color: Sets the color of the bottom border.
    • border-left-color: Sets the color of the left border.
    • border-right-color: Sets the color of the right border.

    Example

    In this example, we have used the CSS border-color property for individual sides to set different border colors for each side of a paragraph element.

    <html><head><style>
    
        p {
            border: solid 7px;
            border-top-color: red; 
            border-right-color: #0000ff; 
            border-bottom-color: rgb(100,123,111); 
            border-left-color: rgba(50,123,111,0.4);
            padding: 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Border Color Individual Sides&lt;/h2&gt;&lt;p&gt;Different border colors on all sides.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Borders Individual Side Shorthand Property

    To apply all the border properties, such as style, width, and color, to just one side of an element, we can make use of the shorthand border property for individual sides. The individual side border shorthand properties are as follows:

    • border-top property: It is a shorthand property for setting the top border properties.
    • border-bottom property: It is a shorthand property for setting the bottom border properties.
    • border-left property: It is a shorthand property for setting the left border properties.
    • border-right property: It is a shorthand property for setting the right border properties.

    Syntax

    The syntax for the individual side border shorthand properties is as follows:

    border-top: 4px solid red;border-bottom: 2px dashed blue;border-left: 6px dotted green;border-right: 8px double yellow;

    Example

    In this example, we have used the border shorthand property for individual sides to set different borders on each side.

    <html><head><style>
    
        p {
            border-top: red dashed thick;
            border-right: solid #0000ff medium;
            border-bottom: thin dotted rgb(100,123,111);
            border-left: rgba(50,123,111,0.4) 15px double;
            padding: 5px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt; Check out borders of paragraph !!!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Override border Shorthand Property

    You can override the border shorthand property by using any individual border property. See the following sample code to clarify this point:

    div{border: 5px solid gray;border-bottom-width: 15px;}

    The above code will have a 5px thick, solid, and gray border on all the sides except for the bottom where the width will be 15px.

    Example

    Here is an example of overriding the border shorthand property:

    <html><head><style>
    
        div {
            padding: 10px;
            border: 5px solid gray;
            border-bottom-width: 15px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt; Check the borders!!! &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Applying Borders to Inline Elements

    Borders can be given to any inline element in a similar manner. The border's thickness will not have any effect on the line height of the element. If left and right borders are specified in an inline element, it will displace the text around the border. Here is an example of applying a border to an inline element.

    Example

    In this example, we have used the border property on span (inline element).

    <html><head><style>
    
        span {
            border: 5px solid black;
            background-color: silver;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt; 
        Check the &lt;span&gt;inline elements&lt;/span&gt; with 
        borders and rest has no border.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS border-image Property

    To set images as borders for another element like div, span, body, paragraph, etc, you can use the border-image property. First you need to declare the border-style property before providing an image source, else no image will be displayed as the border.

    Example

    Here is an example of using the border-image property to set an image as the border of

    <html><head><style>
    
        div{
            background-color: #f0f0f0;
            border: 20px solid transparent;
            border-image: url(/css/images/border.png) 40;
            padding: 20px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;&lt;p&gt;
            This is an example of setting a 
            border image using CSS
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS border-radius Property

    CSS border-radius property is used to specify the roundness of border edges. The value for this property can be in length (px, em) or percentages. A border radius of 50% indicates a complete circle.

    Example

    In this example, we have created a rounded square and a circle using the border-radius property.

    <html><head><style>
    
         div{
            background-color: #00f9f9;
            height: 150px;
            width: 150px;
            text-align: center;
        }
        .round{
            border-radius: 20px;
        }
        .fullRound{
            border-radius: 50%;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="round"&gt;
        Round edged div
    &lt;/div&gt;&lt;div class="fullRound"&gt;
        Circular Div
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Borders All Properties

    All the properties related to the border are listed in the table below:

    PropertyDescriptionExample
    borderA shorthand property for setting all the border properties in one declarationTry It
    border-colorA shorthand property for setting border color of an element.Try It
    border-styleA shorthand property for setting style (solid / dashed) of border of an elementTry It
    border-widthA shorthand property for setting border width of an element.Try It
    border-bottomA shorthand property for setting bottom border of an element.Try It
    border-bottom-colorSets the color of bottom border of an element.Try It
    border-bottom-widthSets the width of bottom border of an element.Try It
    border-bottom-styleSets the style of bottom border of an element.Try It
    border-leftA shorthand property for setting left border of an element.Try It
    border-left-colorSets the color of left border of an element.Try It
    border-left-widthSets the width of left border of an element.Try It
    border-left-styleSets the style of left border of an element.Try It
    border-rightA shorthand property for setting right border of an element.Try It
    border-right-colorSets the color of right border of an element.Try It
    border-right-widthSets the width of right border of an element.Try It
    border-right-styleSets the style of right border of an element.Try It
    border-topA shorthand property for setting top border of an element.Try It
    border-top-colorSets the color of top border of an element.Try It
    border-top-widthSets the width of top border of an element.Try It
    border-top-styleSets the style of top border of an element.Try It
    border-imageA shorthand property for setting border image.Try It
    border-image-outsetSets the image outset i.e how much the border image area extends beyond the border box.Try It
    border-image-repeatThis property determines whether the border image should be repeated, rounded, spaced or stretched.Try It
    border-image-sourceSets the source/path of an image to be passed as a border to an element.Try It
    border-image-sliceThis property shows how to slice up an image in a border.Try It
    border-image-widthSets the width of the image to be set as a border.Try It

  • Styling Tables

    Styling tables in a webpage involves using CSS properties to customize the appearance of tables. CSS properties such as border-collapse, border-spacing, and caption-side can be applied to tables to control the borders, spacing, and alignment of the table and its cells.

    This chapter discusses how to set different properties of an HTML table using CSS.

    CSS Table Border Styling

    To style table borders, we use CSS properties like border and border-radius. You can set the border’s width, color, and style with border property on the table, rows, or individual cells.

    • border: CSS border property sets the width, style, and color of all four sides of the table border (e.g., border: 1px solid black;).
    • border-radius: CSS border-radius property rounds the corners of the table border (e.g., border-radius: 5px|50%).

    Example

    In this example, we have set the rounded table border using CSS border and border-radius property.

    <!DOCTYPE html><html><head><style>
    
        table {
            border-radius: 10px;
            border: 2px solid #031926;
            width: 100%;
        }
        td {
            border: 1px solid black;
            height: 50px;
            vertical-align: middle;
            text-align: center;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;th&gt;Header 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Table Border Collapse

    To merge the cell borders of the table or keep the cell borders separated, the border-collapse property is used. To merge the cell borders, collapse value is used while separate value keeps the border distinct.

    Example

    In the following example, we have used border-collapse property with collapse and separate values.

    <!DOCTYPE html><html><head><style>
    
        table {
            border: 3px solid purple;
        }
        th, td {
            border: 1px solid black;
            padding: 6px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt; border-collapse: separate &lt;/h2&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;h2&gt; border-collapse: collapse &lt;/h2&gt;&lt;table style="border-collapse: collapse;"&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Table Border Spacing

    To set the distance separating adjacent cell borders in a table, the border-spacing property is used. This property may be specified as either one or two values.

    • border-spacing: 2px: It applies 2px spacing to both vertical and horizontal borders.
    • border-spacing: 1cm 2em: In this case, the first value defines the horizontal spacing between cells (i.e., the space between cells in adjacent columns), and the second value defines the vertical spacing between cells (i.e., the space between cells in adjacent rows).

    Example

    In this example, we have set the border-spacing property to 1em horizontally and 0.5em vertically.

    <!DOCTYPE html><html><head><style>
    
        table {
            border-collapse: separate;
            border-spacing: 1em 0.5em;
            border: 3px solid;
        }
        td {
            width: 1.5em;
            height: 1.5em;
            border: 1px solid black;
            text-align: center;
            vertical-align: middle;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Note: The border-spacing property only works when border-collapse is set to separate. If you set border-collapse to collapse, the border-spacing property will have no effect, and the borders will collapse into a single line.

    CSS Tables Caption Side

    To control the placement of the table caption, the caption-side property is used.

    Example

    In this example, we have used the caption-side property to place the table caption at the top and bottom of the table in the first and second table respectively.

    <!DOCTYPE html><html><head><style>
    
        .top caption {
            caption-side: top;
        }
        .bottom caption {
            caption-side: bottom;
        }
        table {
            border: 1px solid red;
        }
        td {
            border: 1px solid blue;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;table class="top"&gt;&lt;caption&gt;
            Caption ABOVE the table
        &lt;/caption&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;table class="bottom"&gt;&lt;caption&gt;
            Caption BELOW the table
        &lt;/caption&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Tables Empty Cells

    To render the empty cells of the table, the empty-cells property is used. The empty-cell property is applied only to tables and table cells. It has the following two values:

    • show: It is the default value that indicates that empty cells should be shown with borders and spacing as if they contained content.
    • hide: It indicates that empty cells should be hidden and not take up any space. Borders and spacing for empty cells will not be displayed.

    Example

    In this example, we have used the empty-cells property with show and hide value to show and hide the empty cells respectively.

    <!DOCTYPE html><html><head><style>
    
        table {
            width: 350px;
            border-collapse: separate;
            empty-cells: show;
        }
        td,th {
            padding: 5px;
            border-style: solid;
            border-width: 1px;
            border-color: #999999;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt; Empty Cells: Show &lt;/h2&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;h2&gt; Empty Cells: Hide &lt;/h2&gt;&lt;table style="empty-cells: hide;"&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Table Layout

    CSS table-layout property is used to control how a browser should render a table. It defines the algorithm used to lay out table cells, rows, and columns. It has the following property values:

    • auto: It is the default value where the browser calculates the width of columns and cells based on the content.
    • fixed: It sets a fixed column width based on the specified table or column width. If width isn't specified, then the first row is used to determine column width and the rest of the rows follow the same column widths irrespective of the content.

    Example

    In this example, the table-layout property is used with auto and fixed values.

    <!DOCTYPE html><html><head><style>
    
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid black;
            padding: 8px;
            text-align: center;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Table with fixed layout&lt;/h2&gt;&lt;table style="table-layout: fixed; "&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Row 1, Column 1&lt;/td&gt;&lt;td&gt;Row 1, Column 2&lt;/td&gt;&lt;td&gt;Row 1, Column 3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Row 2, Column 1&lt;/td&gt;&lt;td&gt;Row 2, Column 2&lt;/td&gt;&lt;td&gt;Row 2, Column 3&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;h2&gt;Table with auto layout&lt;/h2&gt;&lt;table style="table-layout: auto; "&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;This is some longer content in Column 1&lt;/td&gt;&lt;td&gt;Short content&lt;/td&gt;&lt;td&gt;Even longer content that might wrap in Column 3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Row 2, Column 1&lt;/td&gt;&lt;td&gt;Row 2, Column 2&lt;/td&gt;&lt;td&gt;Row 2, Column 3&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Note: The fixed table layout is faster than auto, as the fixed value does not depend on the table's content but rather on the table's width.

    CSS Table Contents Alignment

    To align the content of table cells, CSS properties such as text-align and vertical-align properties are used.

    • text-align: It sets the horizontal alignment of the text content within table cells. It can have values like left, right, center, and justify.
    • CSS vertical-align: It sets the vertical alignment of the content within table cells. It can have values like top, bottom, and middle.

    Example

    In this example, we have used the text-align and vertical-align properties to align the text content horizontally and vertically.

    <!DOCTYPE html><html><head><style>
    
        table, td, th {
            border: 2px solid black;
        }
        table {
            border-collapse: collapse;
        }
        td {
            width: 100px;
            height: 70px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;th&gt;Header 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td style="text-align: center;"&gt;Data Center&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td style="vertical-align: bottom"&gt;Data Bottom&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td style="vertical-align: top"&gt;Data Top&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Note: The default horizontal alignment of <th> and <td> is center and left respectively. The default vertical alignment of both <th> and <td> is middle.

    CSS Tables Background color

    To set the background color of the cell, row, or entire table, the CSS background-color property is used.

    Syntax

    The syntax for setting the background color of the cell, row, and table is as follows:

    /* To set the background color of table */table{background-color: #f2f2f2;}/* To set the background color of a cell a row */td{background-color: #f2f2f2;}/* To set the background color of a row */tr{background-color: #ffffff;}

    Example

    In this example, we have set the background color of the table using the element selector. To set the background color of the row and a cell, we have used inline CSS.

    <!DOCTYPE html><html><head><style>
    
        table {
            border: 2px solid black;
            background-color: rgb(237, 181, 237);
            width: 100%;
            border-collapse: collapse;
        }
        td {
            height: 50px;
            vertical-align: middle;
            text-align: center;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Background color property&lt;/h2&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;th&gt;Header 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td style="background-color: #f0f0ff;"&gt; Data 2&lt;/td&gt;&lt;td&gt;Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;tr style="background-color: #04af2f;"&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Table Text Font Styles

    To style the text content of the table, we can use CSS font properties such as font-size, font-family, font-weight, etc. on the table elements.

    Example

    In this example, we have set the font-size and font-family of the th and td tags.

    <!DOCTYPE html><html><head><style>
    
        table.one {
            border-collapse: collapse;
            width: 400px;
        }
        th {
            font-size: large;
            font-family: 'Lucida Sans', sans-serif;
        }
        td {
            font-size: small;
            font-family: Verdana, Geneva, Tahoma, sans-serif;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;font styles&lt;/h2&gt;&lt;div&gt;&lt;table class = "one" border = "1"&gt;&lt;th&gt;Heading&lt;/th&gt;&lt;tr&gt;&lt;td&gt; Cell value&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Cell value&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Table Dividers

    Dividers in a table are used to separate the content of the table and make it more readable. To set a vertical divider, the border-right property is used whereas border-bottom property is used to set a horizontal divider.

    Example

    In this example, we have set the vertical divider using the border-right property and the horizontal divider using the border-bottom property.

    <!DOCTYPE html><html><head><style>
    
        table {
            border: 2px solid black;
            background-color: rgb(200, 240, 210);
            border-collapse: collapse;
            width: 100%;
        }
        th {
            border-bottom: 2px solid black;
            padding: 5px;
        }
        td {
            border-bottom: 1px solid grey;
            padding: 5px;
            text-align: center;
        }
        .vDiv {
            border-right: 2px solid black;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Horizontal Divider&lt;/h2&gt;&lt;table&gt;&lt;tr&gt;&lt;th class="vDiv"&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="vDiv"&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="vDiv"&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="vDiv"&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Striped Table

    A striped table is a table that has alternating background colors for rows, making it easier to read and understand the data. To create a striped table, the nth-child selector is used to apply different background colors to odd and even rows.

    Example

    In this example, we have used the nth-child selector to set the green and light green background color of the cells creating a striped table.

    <!DOCTYPE html><html><head><style>
    
        table {
            border-collapse: collapse;
            width: 100%;
            color: white;
        }
        th, td {
            text-align: left;
            padding: 8px;
        }
        tr:nth-child(odd) {
            background-color: rgba(4, 175, 47, 1);
        }
        tr:nth-child(even) {
            background-color: rgba(4, 175, 47, 0.4);
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Striped table&lt;/h2&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;th&gt;Header 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Data 1&lt;/td&gt;&lt;td&gt; Data 2&lt;/td&gt;&lt;td&gt; Data 3&lt;/td&gt;&lt;td&gt; Data 4&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Responsive Table

    A responsive table refers to a table that adjusts and adapts its layout and formatting based on different screen sizes and resolutions. You can use the overflow-x property to add a horizontal scroll bar to the table in small screen sizes when the entire screen is not seen.

    Example

    In this example, we have used overflow-x property to add a horizontal scroll to adjust to smaller screens.

    <!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=device-width, 
    
          initial-scale=1.0"&gt;&lt;style&gt;
        .responsive-table {
            width: 100%;
            border-collapse: collapse;
            overflow-x: auto;
            display: block;
        }
        .responsive-table th, .responsive-table td {
            text-align: left;
            padding: 8px;
            border: 1px solid #ddd;
        }
        .responsive-table th {
            background-color: #f2f2f2;
        }
        .responsive-table tr:nth-child(odd) {
            background-color: #f9f9f9;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Responsive Table&lt;/h2&gt;&lt;table class="responsive-table"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;th&gt;Header 4&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Data 1&lt;/td&gt;&lt;td&gt;Data 2&lt;/td&gt;&lt;td&gt;Data 3&lt;/td&gt;&lt;td&gt;Data 4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Data 5&lt;/td&gt;&lt;td&gt;Data 6&lt;/td&gt;&lt;td&gt;Data 7&lt;/td&gt;&lt;td&gt;Data 8&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Data 9&lt;/td&gt;&lt;td&gt;Data 10&lt;/td&gt;&lt;td&gt;Data 11&lt;/td&gt;&lt;td&gt;Data 12&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>