Category: Basic

  • character Property

    CSS hyphenate-character property allows you to specify the character that should be used as the hyphenation point when text is hyphenated using the hyphens property. When text is hyphenated, the browser will insert a hyphen character at appropriate points within words.

    Syntax

    hyphenate-character: auto | string | initial | inherit;

    Property Values

    ValueDescription
    autoSuitable character is selected by the browser based on the current typography conventions. Default.
    stringIt specifies the character to be used at the end of line before a hyphenation break.
    initialThis sets the property to its default value.
    inheritThis inherits the property from the parent element.

    Examples of CSS Hyphenate Character Property

    The following examples explain the hyphenate-character property with different values.

    Hyphenate Character Property with Auto Value

    To allow the browser to use its default hyphenation character for breaking words which typically is a standard hyphen (-) or another character defined by the browsers settings for hyphenation, we use the auto value. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      div {
         width: 80px;
         border: 2px solid blue;
         hyphens: auto;
         hyphenate-character: auto;
      }
    </style></head><body><h2>
      CSS hyphenate-character property
    </h2><h4>
      hyphenate-character: auto
    </h4><div>
      CSS hyphenatecharacter auto
    </div></body></html>

    Hyphenate Character Property with String Value

    To use different characters for hyphenation, we specify the character in string to the hyphenate-character property. The specified character(s) will be used as the hyphenation character when breaking words. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      div {
         width: 80px;
         border: 2px solid blue;
         hyphens: auto;
      }
      .box1 {
         hyphenate-character: "=";
      }
      .box2 {
         hyphenate-character: "*";
      }
      .box3 {
         hyphenate-character: "%";
      }
    </style></head><body><h2>
      CSS hyphenate-character property
    </h2><h4>hyphenate-character: "="</h4><div class="box1">
      CSS hyphenatecharacter "="
    </div><h4>hyphenate-character: "*"</h4><div class="box2">
      CSS hyphenatecharacter "*"
    </div><h4>hyphenate-character: "%"</h4><div class="box3">
      CSS hyphenatecharacter "%"
    </div></body></html>
  • height Property

    CSS height property specifies the height of an element. It determines how tall an element will be, affecting its layout and positioning within the document. The property can be applied to block-level elements, inline-block elements, and replaced elements like images.

    Syntax

    height: auto | length | percentage | min-content | max-content | initial | inherit;

    Property Values

    ValueDescription
    autoThe element expands or contracts based on its content. Default.
    lengthIt sets a fixed height for the element using length units (e.g. px, em, rem etc.)
    percentageIt sets the height as a percentage of the height of the element’s containing block.
    min-contentIt makes the element’s height fit the minimum height required by its content, preventing content from overflowing.
    max-contentIt adjusts the element height to fit the tallest content without wrapping or truncating it.
    initialThis sets the property to its default value.
    inheritThis inherits the property from the parent element.

    Examples of CSS Height Property

    The following examples explain the height property with different values.

    Height Property with Auto Value

    To allow the height of an element to be dependent on the length of its content, we use the auto value. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .outer {
         background-color: lightgrey;
         height: 200px;
         padding: 10px;
         box-sizing: border-box;
      }
      .inner {
         text-align: center;
         border: 2px solid;
         background-color: lightblue;
         height: auto;
      }
    </style></head><body><h2>
      CSS height property
    </h2><h4>
      height: auto
    </h4><div class="outer"><div class="inner">
         This div is having auto height. 
         The height of this div depends on the content.
      &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Height Property with Length Values

    To set a fixed height to an element, we use the length units (e.g. px, em, rem etc.). The element will be having a fixed height, if the content of the element is larger than the size of the element, overflow will occur. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .outer {
         background-color: lightgrey;
         height: 200px;
         padding: 10px;
         box-sizing: border-box;
      }
      .inner {
         text-align: center;
         border: 2px solid;
         background-color: lightblue;
      }
      .inner1 {
         height: 40px;
      }
      .inner2 {
         height: 90px;
      }
    </style></head><body><h2>
      CSS height property
    </h2><h4>
      height: 40px 90px
    </h4><div class="outer"><p class="inner inner1">
         This paragraph is having 40px height.
      &lt;/p&gt;&lt;p class="inner inner2"&gt;
         This paragraph is having 90px height.
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Height Property with Percentage Values

    To set a fixed height to an element, we use the percentage values (e.g. 10%, 20% etc.). The element's height will be relative to the height of its containing block. If the content of the element is greater than the size, overflow will occur. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .outer {
         background-color: lightgrey;
         height: 300px;
         padding: 10px;
         box-sizing: border-box;
      }
      .inner {
         text-align: center;
         border: 2px solid;
         background-color: lightblue;
      }
      .inner1 {
         height: 30%;
      }
      .inner2 {
         height: 50%;
      }
    </style></head><body><h2>
      CSS height property
    </h2><h4>
      height: 30% 50%
    </h4><div class="outer"><p class="inner inner1">
         This paragraph is having 30% 
         height of the outer container.
      &lt;/p&gt;&lt;p class="inner inner2"&gt;
         This paragraph is having 50% 
         height of the outer container.
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Height Property with Min Content Value

    To set the element height to the minimum size required to fit its content without overflow, we use the min-content value. This ensures that the height is just enough to display the content in a single line without wrapping or truncation. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .outer {
         background-color: lightgrey;
         height: 200px;
         padding: 10px;
         box-sizing: border-box;
      }
      .inner {
         text-align: center;
         border: 2px solid;
         background-color: lightblue;
         height: min-content;
      }
    </style></head><body><h2>
      CSS height property
    </h2><h4>
      height: min-content
    </h4><div class="outer"><p class="inner ">
         TutorialsPoint is an online educational
         platform offering a vast range of tutorials
         and courses on programming, web development, 
         data science, and other technical subjects, 
         featuring detailed guides and interactive
         content.
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Height Property with Max Content Value

    To adjust the element height to fit the tallest content within it, we use the max-content. The height expands to accommodate the largest item or content, ensuring that no content is cut off or wrapped. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .outer {
         background-color: lightgrey;
         height: 200px;
         padding: 10px;
         box-sizing: border-box;
      }
      .inner {
         text-align: center;
         border: 2px solid;
         background-color: lightblue;
         height: max-content;
      }
    </style></head><body><h2>
      CSS height property
    </h2><h4>
      height: max-content
    </h4><div class="outer"><p class="inner ">
         TutorialsPoint is an online educational
         platform offering a vast range of tutorials
         and courses on programming, web development, 
         data science, and other technical subjects, 
         featuring detailed guides and interactive 
         content.
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>
  • translate Property

    The translate Property

    The translate property of CSS allows you to move an element along the X-axis (horizontal), Y-axis (vertical), and Z-axis (depth).

    The translate property is similar to the translate() function of the transform property. The only difference between the two is that the latter does not support the Z-axis setting.

    Syntax

    The syntax for the CSS translate property is as follows:

    translate: x-axis y-axis z-axis | none;

    Possible values

    ValueDescription
    noneIt specifies no translation should be applied.
    x-axisIt specifies translation along the X-axis. If one value is specified with the translate property, then it specifies translation in the x-axis.
    y-axisIt specifies translation along the Y-axis. If two values are specified with the translate property, then the first value specifies translation in the x-axis and the second value in the y-axis. To specify translation only the in y-axis, specify the first value as 0px.
    z-axisIt specifies translation along the Z-axis. If three values are specified with the translate property, then the first, second, and third value specifies translation in the x-axis, y-axis, and z-axis respectively. To specify translation only in the z-axis, specify the first two values as 0px.

    You can use either <length> or <percentage> to specify the value of the translate property.

    Applies to

    All the transformable elements.

    CSS translate Property with none Value

    To specify that there should not be any translation effect on any axis, we use the translate property with none value.

    Example

    The following example sets the translate property to none which disables the translation effect on the div box.

    <html><head><style>
    
        .box {
            height: 100px;
            width: 100px;
            display: inline-block;
            padding: 10px;
            border: 1px solid black;
            transition: all 0.3s ease;
        }
        .box:hover {
            background-color: #04af2f;
            translate: none;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="box"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS translate on X-Axis

    You can use a single value with the translate property to move an element on the horizontal axis. You can either use length or percentage value for this.

    Example

    In this example, we have used a positive length value on the first box and a negative percentage value on the second box with the translate property. The first box will move to the right and the second box will move to the left on the x-axis.

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            height: 100px;
            width: 200px;
            padding: 10px;
            border: 1px solid black;
            margin: auto;
            display: flex;
            justify-content: space-around;
            align-items: center;
            background-color: #f0f0ff;            
        }
        .box {
            height: 80px;
            width: 80px;
            border: 1px solid black;
            display: inline-block;
            transition: all 0.3s ease;
            background-color: white;
        }
        .box1:hover {
            background-color: #04af2f;
            translate: 10px;
        }
        .box2:hover {
            background-color: #031926;
            translate: -10%;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS translate Property&lt;/h2&gt;&lt;p&gt;Translation on x-axis.&lt;/p&gt;&lt;div class="container"&gt;&lt;div class="box box1"&gt;&lt;/div&gt;&lt;div class="box box2"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS translate on Y-Axis

    To translate an element on the y-axis, you need to use a double value with the translate property while setting the first value to 0.

    Example

    In this example, we have used a positive length value on the first box and a negative percentage value on the second box with the translate property. The first box will move downwards and the second box will move upwards on the y-axis.

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            height: 150px;
            width: 200px;
            padding: 10px;
            border: 1px solid black;
            margin: auto;
            display: flex;
            justify-content: space-around;
            align-items: center;
            background-color: #f0f0ff;            
        }
        .box {
            height: 80px;
            width: 80px;
            border: 1px solid black;
            display: inline-block;
            transition: all 0.3s ease;
            background-color: white;
        }
        .box1:hover {
            background-color: #04af2f;
            translate: 0px 15px;
        }
        .box2:hover {
            background-color: #031926;
            translate: 0% -15%;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS translate Property&lt;/h2&gt;&lt;p&gt;Translation on y-axis.&lt;/p&gt;&lt;div class="container"&gt;&lt;div class="box box1"&gt;&lt;/div&gt;&lt;div class="box box2"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS translate on Z-Axis

    To translate an element on the z-axis, you need to use a triple value with the translate property while setting the first two values to 0.

    Example

    In this example, we have used a positive and negative length value on the first box and second box respectively with the translate property. The first box will appear to move closer to the screen while the second box will move away from the screen.

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            perspective: 100px;
            height: 150px;
            width: 200px;
            padding: 10px;
            border: 1px solid black;
            margin: auto;
            display: flex;
            justify-content: space-around;
            align-items: center;
            background-color: #f0f0ff;            
        }
        .box {
            height: 80px;
            width: 80px;
            border: 1px solid black;
            display: inline-block;
            transition: all 0.3s ease;
            background-color: white;
        }
        .box1:hover {
            background-color: #04af2f;
            translate: 0 0 15px;
        }
        .box2:hover {
            background-color: #031926;
            translate: 0 0 -10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS translate Property&lt;/h2&gt;&lt;p&gt;Translation on z-axis.&lt;/p&gt;&lt;div class="container"&gt;&lt;div class="box box1"&gt;&lt;/div&gt;&lt;div class="box box2"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS translate on X and Y Axes

    You can translate an element on both the x and y axes by using a double value with the translate property.

    Example

    In this example, we have used two values with the translate property. The first and second value moves the box in horizontal and vertical directions respectively.

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            height: 150px;
            width: 250px;
            padding: 10px;
            border: 1px solid black;
            margin: auto;
            display: flex;
            justify-content: space-around;
            align-items: center;
            background-color: #f0f0ff;            
        }
        .box {
            height: 80px;
            width: 80px;
            border: 1px solid black;
            display: inline-block;
            transition: all 0.3s ease;
            background-color: white;
        }
        .box1:hover {
            background-color: #04af2f;
            translate: 15px 10px;
        }
        .box2:hover {
            background-color: #031926;
            translate: -15% -15%;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS translate Property&lt;/h2&gt;&lt;p&gt;Translation on both x and y-axis.&lt;/p&gt;&lt;div class="container"&gt;&lt;div class="box box1"&gt;&lt;/div&gt;&lt;div class="box box2"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS translate on Y and Z Axes

    You can translate an element on both the y and z-axes by using a double value with the translate property while setting the x-axes value as 0.

    Example

    In this example, we have used two values with the translate property. The second and third value moves the box to the y-axis and z-axis respectively.

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            perspective: 100px;
            height: 150px;
            width: 250px;
            padding: 10px;
            border: 1px solid black;
            margin: auto;
            display: flex;
            justify-content: space-around;
            align-items: center;
            background-color: #f0f0ff;            
        }
        .box {
            height: 80px;
            width: 80px;
            border: 1px solid black;
            display: inline-block;
            transition: all 0.3s ease;
            background-color: white;
        }
        .box1:hover {
            background-color: #04af2f;
            translate: 0px 15px 10px;
        }
        .box2:hover {
            background-color: #031926;
            translate:0 -15% 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS translate Property&lt;/h2&gt;&lt;p&gt;Translation on both y and z-axis.&lt;/p&gt;&lt;div class="container"&gt;&lt;div class="box box1"&gt;&lt;/div&gt;&lt;div class="box box2"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS translate on X and Z Axes

    To translate an element on both the x and z-axes, you can use a double value with the translate property while setting the y-axis value to 0.

    Example

    In this example, we have used two values with the translate property. The first and third value moves the box to the x-axis and z-axis respectively.

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            perspective: 100px;
            height: 150px;
            width: 250px;
            padding: 10px;
            border: 1px solid black;
            margin: auto;
            display: flex;
            justify-content: space-around;
            align-items: center;
            background-color: #f0f0ff;            
        }
        .box {
            height: 80px;
            width: 80px;
            border: 1px solid black;
            display: inline-block;
            transition: all 0.3s ease;
            background-color: white;
        }
        .box1:hover {
            background-color: #04af2f;
            translate: 15px 0 15px;
        }
        .box2:hover {
            background-color: #031926;
            translate: -15% 0 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS translate Property&lt;/h2&gt;&lt;p&gt;Translation on both x and z-axis.&lt;/p&gt;&lt;div class="container"&gt;&lt;div class="box box1"&gt;&lt;/div&gt;&lt;div class="box box2"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS translate on X, Y and Z Axes

    To translate an element in all directions, you can use three values with the translate property.

    Example

    In this example, we have used three values with the translate property. The first, second, and third value moves the box horizontally, vertically, and in the z-axis respectively.

    <!DOCTYPE html><html lang="en"><head><style>
    
        .container {
            perspective: 100px;
            height: 150px;
            width: 250px;
            padding: 10px;
            border: 1px solid black;
            margin: auto;
            display: flex;
            justify-content: space-around;
            align-items: center;
            background-color: #f0f0ff;            
        }
        .box {
            height: 80px;
            width: 80px;
            border: 1px solid black;
            display: inline-block;
            transition: all 0.3s ease;
            background-color: white;
        }
        .box1:hover {
            background-color: #04af2f;
            translate: 15px 15% 15px;
        }
        .box2:hover {
            background-color: #031926;
            translate: -15% -10px 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS translate Property&lt;/h2&gt;&lt;p&gt;Translation on x,y, and z-axis.&lt;/p&gt;&lt;div class="container"&gt;&lt;div class="box box1"&gt;&lt;/div&gt;&lt;div class="box box2"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>
  • zoom Property

    The zoom Property

    CSS zoom property is used to control the magnification level of HTML elements. The zoom property is a non-standard property of CSS and it is advisable to use the scale() function with the transform property to achieve the same output.

    Syntax

    The syntax for the CSS zoom property is as follows:

    zoom: normal | percentage | number;

    Possible Values

    ValueDescription
    normalIt specifies that the element should be rendered at its normal size.
    <percentage>It specifies the zoom factor in percent value. A value equal to 100% specifies normal size. The value less than 100% specifies zoom-out, and the value more than 100% specifies zoom-in.
    <number>It specifies the zoom factor in the number value. A value equal to 1.0 specifies normal size. The value less than 1.0 specifies zoom-out, and the value more than 1.0 specifies zoom-in.

    Applies to

    The zoom property can be applied to all the HTML elements.

    CSS zoom Property with normal Value

    The normal is the default value of the zoom property. The element appears at its regular size with zoom:normal.

    Example

    In this example, we have used the default value(normal) of the zoom property.

    <html><style>
    
    .normal {
        zoom: normal;
    }
    </style><head></head><body><h2>CSS zoom Property</h2><p class="normal">CSS zoom with normal value.</p></body></html>

    CSS zoom Property with percent Value

    You can use the zoom property with percent value to add a zoom-in or zoom-out effect to any element.

    Example

    In this example, we have used the percentage value > 100% to create a zoom-in effect on a div box upon hovering over it.

    <html><head><style>
    
        .box {
            height: 50px;
            width: 200px;
            border: 1px solid black;
            text-align: center;
            transition: all 0.3s ease;
            position: relative;
        }
        .box:hover {
            zoom: 2;
        }
        .box::before {
            content: "This is a normal box";
        }
        .box:hover::before {
            content: "";
        }
        .box:hover::after {
            content: "This is after applying zoom with percent value.";
            display: block;
            position: absolute;
            width: 100%;
            text-align: center;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS zoom Property with Percent&lt;/h2&gt;&lt;div class="box"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS zoom Property with numeric Value

    To add a zoom-in or zoom-out effect to any element, you can use the zoom property with a numeric value.

    Example

    In this example, we have used the numeric value > 1 to create a zoom-in effect on a div box upon hovering over it.

    <html><head><style>
    
        .box {
            height: 50px;
            width: 200px;
            border: 1px solid black;
            text-align: center;
            transition: all 0.3s ease;
            position: relative;
        }
        .box:hover {
            zoom: 2;
        }
        .box::before {
            content: "This is a normal box";
        }
        .box:hover::before {
            content: "";
        }
        .box:hover::after {
            content: "This is after applying zoom";
            display: block;
            position: absolute;
            width: 100%;
            text-align: center;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS zoom Property with Number&lt;/h2&gt;&lt;div class="box"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS zoom Property with Transition

    You can use transition with the zoom property to create a smooth zoom-in or zoom-out effect.

    Example

    In this example, we have created three div boxes that create a smooth zoom-in effect upon hovering over them.

    <html><head><style>
       div.box {
    
      width: 25px;
      height: 25px;
      vertical-align: middle;
      display: inline-block;
      transition: transform .5s;
      padding: 10px;
    } div#a {
      background-color: rgb(58, 220, 22);
      zoom: normal;
    } div#b {
      background-color: rgb(239, 86, 137);
      zoom: 200%;
    } div#c {
      background-color: rgb(223, 217, 44);
      zoom: 2.9;
    } div.box:hover {
      transform: scale(1.5);
    } </style></head><body><h1>Animation added on hover</h1><div id="a" class="box"></div><div id="b" class="box"></div><div id="c" class="box"></div></body></html>
  • Focus Effects

    CSS focus effects are used to make form elements like input fields, buttons, and links more dynamic and engaging for users interacting with the webpage.

    The :focus pseudo-class in CSS is used to target an element when it receives focus (by clicking on it or by pressing tab). Its purpose is to apply styles or trigger specific behaviors to enhance the user experience or provide additional visual feedback.

    Focus on me!

    The :focus is a tool to make interactive elements more dynamic and engaging, especially when users navigate using the keyboard.

    Table of Contents

    • What is Focus Pseudo-Class?
    • CSS Focus Effect on Input Field
    • CSS Button With Focus Effect
    • CSS Border With Focus Effect
    • CSS Box-Shadow With Focus Effect
    • CSS Styling on Focusing

    What is Focus Pseudo-Class?

    • In CSS, the pseudo-class :focus is a type of selector used to target and style an element when it gains focus, usually through keyboard navigation or mouse interaction.
    • Focus effects are mostly used with interactive elements like form fields, buttons, etc., to provide users a clear indication of the focused element.
    • Focus effects are useful to add a dynamic and engaging look to a website and improve accessibility.

    CSS Focus Effect on Input Field

    Here is an example of styling input fields when they receive focus:

    Example

    <!DOCTYPE html><html><head><style>
    
        .input-field {
            width: 80%; 
            height: 30px; 
            padding: 5px;
            margin: 10px 0;
            background-color: #f0f0f0; 
            border: 1px solid black; 
            font-size: 16px;
            outline: none;
        }
        .input-field:focus {
            border: 3px solid darkblue;
            padding: 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="main"&gt;&lt;input type="text" class="input-field" 
               placeholder="Enter your name" tabindex="0"&gt;&lt;input type="text" class="input-field" 
               placeholder="Enter your email" tabindex="1"&gt;&lt;input type="text" class="input-field" 
               placeholder="Enter your password" tabindex="2"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Button With Focus Effect

    Here is an example of styling a button in a focused state.

    Example

    <!DOCTYPE html><html><head><style>
    
        button {
            padding: 10px 20px;
            margin: 10px;
            background-color: #ffffff;
            color: #228B22;
            border: 2px solid #228B22;
            border-radius: 5px;
            text-decoration: none;
            font-size: 16px;
            font-weight: bold;
            transition: background-color 0.3s, color 0.3s;
        }
        button:focus {
            background-color: #FFCC33;
            color: #ffffff;
            outline: none;
            transform: scale(1.2);
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;button&gt; Focus on me! &lt;/button&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Border With Focus Effect

    Here is an example that shows how the border is changing when the element receives focus:

    Example

    <!DOCTYPE html><html><head><style>
    
        div {
            padding: 10px 20px;
            margin: 10px;
            background-color: #228B22;
            color: #ffffff;
            border: 2px solid #228B22;
            border-radius: 5px;
            text-decoration: none;
            font-size: 16px;
            font-weight: bold;
            transition: all 0.3s;
        }
        div:focus {
            border-radius: 20px;
            outline: none;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div tabindex="0"&gt; Focus on me! &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Box-Shadow With Focus Effect

    Here is an example, where box-shadow is added when the div receives focus:

    Example

    <!DOCTYPE html><html><head><style>
    
        div {
            padding: 10px 20px;
            margin: 10px;
            background-color: #228B22;
            color: #ffffff;
            border: 2px solid #228B22;
            border-radius: 5px;
            text-decoration: none;
            font-size: 16px;
            font-weight: bold;
            transition: all 0.3s;
        }
        div:focus {
            box-shadow: 20px 20px 10px grey;
            outline: none;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div tabindex="0"&gt; Focus on me! &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Styling on Focusing

    Here is an example, where a shadow effect is given to a button on focus:

    Example

    <!DOCTYPE html><html><head><style>
    
        body {
            height: 300px;
            overflow: hidden;
            display: grid;
            justify-content: center;
            align-items: center;
        }
    
        .glow {
            padding: 10px;
            width: 250px;
            height: 50px;
            border: none;
            outline: none;
            color: #fff;
            background: #111;
            cursor: pointer;
            position: relative;
            z-index: 0;
            border-radius: 20px;
        }
    
        .glow:before {
            content: '';
            background: linear-gradient(60deg, #ff0000, #ff7300, 
                                #fffb00, #48ff00, #00ffd5, #002bff, 
                                #7a00ff, #ff00c8, #ff0000);
            position: absolute;
            top: -4px;
            left:-4px;
            background-size: 400%;
            z-index: -1;
            filter: blur(15px);
            width: calc(100% + 6px);
            height: calc(100% + 6px);
            animation: glowing 20s linear infinite;
            opacity: 0;
            transition: opacity .3s ease-in-out;
            border-radius: 10px;
        }
    
        .glow:focus:before {
            opacity: 1;
        }
    
        .glow:after {
            z-index: -1;
            content: '';
            position: absolute;
            width: 100%;
            height: 100%;
            background: #111;
            left: 0;
            top: 0;
            border-radius: 10px;
        }
    
        @keyframes glowing {
            0% { 
                background-position: 0 0; 
            }
            50% { 
                background-position: 400% 0; 
            }
            100% { 
                background-position: 0 0; 
            }
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;button class="glow" type="button" tabindex="0"&gt;
        FOCUS ON ME!
    &lt;/button&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • display Property

    The display Property

    CSS display property specifies the behaviour of HTML elements. It defines how an elements is displayed on the webpage.

    Syntax

    display: value;

    Display Property Values

    ValueDescription
    inlineIt displays the element as an inline element on which width and height properties do not have any effect. Default.
    blockIt displays the element as a block element which starts on a new line and takes up the whole width.
    contentsIt make an element disappear from the layout while keeping its child elements visible and in their original positions within the layout.
    flexIt displays an element as a block-level flex container.
    gridIt displays an element as a block-level grid container.
    inline-blockIt allows an element to flow along with other inline elements along with having block-level characteristics such as width and height.
    inline-flexIt displays an element as an inline-level flex container.
    inline-gridIt displays an element as an inline-level grid container.
    inline-tableIt displays the element as an inline-level table.
    run-inIt displays an element depending on context as either block or inline.
    tableIt enables the element to behave like a <table> element.
    table-captionIt enables the element to behave like a <caption> element.
    table-column-groupIt enables the element to behave like a <colgroup> element.
    table-header-groupIt enables the element to behave like a <thead> element.
    table-footer-groupIt enables the element to behave like a <tfoot> element.
    table-row-groupIt enables the element to behave like a <tbody> element
    table-cellIt enables the element to behave like a <td> element.
    table-columnIt enables the element to behave like a <col> element.
    table-rowIt enables the element to behave like a <tr> element.
    noneIt removes the element completely.
    initialThis sets the property to its default value.
    inheritThis inherits the property from the parent element.

    CSS display Property with inline Value

    The following example illustrates the use of inline value on div elements making them appear as inline element.

    Example

    <!DOCTYPE html><html><head><style>
    
      .inline-item {
         display: inline;
         background-color: #4CAF50;
         color: white;
         padding: 10px;
         margin: 5px;
      }
      .container {
         border: 3px solid #ccc;
         padding: 15px;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>
      display: inline 
    </h4><div class="container"><div class="inline-item">
         Item 1
      &lt;/div&gt;&lt;div class="inline-item"&gt;
         Item 2
      &lt;/div&gt;&lt;div class="inline-item"&gt;
         Item 3
      &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS display Property with block Value

    The following example illustrates the use of block value on span elements making them appear as block element.

    Example

    <!DOCTYPE html><html><head><style>
    
      .block-item {
         display: block;
         background-color: #4CAF50;
         color: white;
         padding: 10px;
         margin: 5px;
      }
      .container {
         border: 3px solid #ccc;
         padding: 15px;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>
      display: block 
    </h4><div class="container"><span class="block-item">
         Item 1
      &lt;/span&gt;&lt;span class="block-item"&gt;
         Item 2
      &lt;/span&gt;&lt;span class="block-item"&gt;
         Item 3
      &lt;/span&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS display Property with Contents Value

    The following example illustrates the use of the contents value. In this example, the .child element behaves as direct child of .parent element bypassing the .wrapper element.

    Example

    <!DOCTYPE html><html><head><style>
    
      .wrapper {
         display: contents;
      }
      .child {
         text-align: center;
         background-color: #4CAF50;
         color: white;
         padding: 10px;
         margin: 5px;
      }
      .parent {
         display: block;
         background-color: #f0f0f0;
         padding: 10px;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>
      display: contents
    </h4><div class="parent"><div class="wrapper"><div class="child">
            Child 1
         &lt;/div&gt;&lt;div class="child"&gt;
            Child 2
         &lt;/div&gt;&lt;div class="child"&gt;
            Child 3
         &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS display Property with Flex Value

    To set an element to be a flex container making its children (flex items) layout in a flexible and responsive way, we use the flex value. The container uses the Flexbox layout model, which allows for easy alignment, distribution, and ordering of items along a single axis. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .flex-container {
         display: flex;
         background-color: #f0f0f0;
         padding: 10px;
      }
      .flex-item {
         background-color: #4CAF50;
         color: white;
         padding: 10px;
         margin: 5px;
         flex: 1;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>
      display: flex
    </h4><div class="flex-container"><div class="flex-item">
         Item 1
      &lt;/div&gt;&lt;div class="flex-item"&gt;
         Item 2
      &lt;/div&gt;&lt;div class="flex-item"&gt;
         Item 3
      &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS display Property with Grid Value

    To set an element to be a grid container which uses the grid layout model, allowing for the creation of two-dimensional layouts with rows and columns, we use the grid value. Grid items can be placed and sized explicitly or automatically across the grid. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .grid-container {
         display: grid;
         background-color: #f0f0f0;
         padding: 10px;
         gap: 10px;
      }
      .grid-item {
         background-color: #4CAF50;
         color: white;
         padding: 10px;
         text-align: center;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>
      display: grid
    </h4><div class="grid-container"><div class="grid-item">
         Item 1
      &lt;/div&gt;&lt;div class="grid-item"&gt;
         Item 2
      &lt;/div&gt;&lt;div class="grid-item"&gt;
         Item 3
      &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS display Property with Inline Block Value

    To make an element behave like an inline-level element (allowing it to flow with text and other inline content) while retaining block-level properties such as width and height, we use the inline-block value. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .inline-block-item {
         text-align: center;
         display: inline-block;
         width: 200px;
         background-color: #4CAF50;
         color: white;
         padding: 10px;
         margin: 5px;
      }
      .container {
         border: 3px solid #ccc;
         padding: 15px;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>
      display: inline-block 
    </h4><div class="container"><span class="inline-block-item">
         Item 1
      &lt;/span&gt;&lt;span class="inline-block-item"&gt;
         Item 2
      &lt;/span&gt;&lt;span class="inline-block-item"&gt;
         Item 3
      &lt;/span&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS display Property with Inline Flex Property

    To set an element to be an inline-level flex container making the container behaves like an inline element, flowing with surrounding text or inline elements, while still applying Flexbox layout rules to its children, we use the inline-flex property. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .inline-flex-container {
         display: inline-flex;
         background-color: #f0f0f0;
         padding: 10px;
      }
      .flex-item {
         background-color: #4CAF50;
         color: white;
         padding: 10px;
         margin: 5px;
         flex: 1;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>
      display: inline-flex
    </h4><div class="inline-flex-container"><div class="flex-item">
         Item 1
      &lt;/div&gt;&lt;div class="flex-item"&gt;
         Item 2
      &lt;/div&gt;&lt;div class="flex-item"&gt;
         Item 3
      &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS display Property with Inline Grid Value

    To set an element to be an inline-level grid container such that it behaves like an inline element (flowing with text and other inline content) while using the grid layout model to arrange its children, we use the inline-grid value. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .grid-container {
         display: inline-grid;
         background-color: #f0f0f0;
         padding: 10px;
         gap: 10px;
      }
      .inline-grid-item {
         background-color: #4CAF50;
         color: white;
         padding: 10px;
         text-align: center;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>
      display: inline-grid
    </h4><div class="grid-container"><div class="inline-grid-item">
         Item 1
      &lt;/div&gt;&lt;div class="inline-grid-item"&gt;
         Item 2
      &lt;/div&gt;&lt;div class="inline-grid-item"&gt;
         Item 3
      &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS display Property with Run In Value

    To make an element behave as a block-level element or an inline-level element depending on the context, we use the run-in value. It is intended to allow an element to "run in" with surrounding text or other elements. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .block-container {
         display: block;
         background-color: #f0f0f0;
         padding: 10px;
      }
      .run-in {
         display: run-in;
         background-color: #4CAF50;
         color: white;
         padding: 10px;
         margin: 5px;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>
      display: run-in
    </h4><div class="block-container"><div class="run-in">
         Run-In Element
      &lt;/div&gt;&lt;p&gt;
         This paragraph follows the run-in element. Depending on 
         the browser support, the run-in element might appear 
         as a block or inline element here.
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS display Property with list-item Value

    The following example illustrates the use of list-item value on div elements making them appear as bulleted list.

    Example

    <!DOCTYPE html><html><head><style>
    
      .list-item {
         display: list-item;
         background-color: #4CAF50;
         padding: 10px;
         margin: 10px;
         text-align: center;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h3>
      display: list item
    </h3><div class="list-item">
      Item 1
    </div><div class="list-item">
      Item 2
    </div><div class="list-item">
      Item 3
    </div></body></html>

    CSS display Property with Table Values

    To create table-like layouts with CSS without using HTML table elements, we can use different displays for the table. In the following example, some values tabletable-rowtable-cell and table-caption have been used.

    • table: creates a container that behaves like a <table>,
    • table-cell: styles elements like <td> cells,
    • table-row: defines elements as rows like <tr>,
    • table-caption: functions like a <caption> element, positioning captions for the table.

    Example

    <!DOCTYPE html><html><head><style>
    
      div {
         background-color: #4CAF50;
         color: white;
         display: flex;
         border: 1px solid black;
      }
      .table {
         display: table;
      }
      .row {
         display: table-row;
         padding: 3px;
      }
      .cell {
         display: table-cell;
         padding: 3px;
      }
      .caption {
         display: table-caption;
         text-align: center;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>
      display: table, table-row, table-cell, table-caption
    </h4><div class="table"><div class="caption">
         Sample Table
      &lt;/div&gt;&lt;div class="row"&gt;&lt;div class="cell"&gt;
            Row1-Cell1
         &lt;/div&gt;&lt;div class="cell"&gt;
            Row1-Cell2
         &lt;/div&gt;&lt;div class="cell"&gt;
            Row1-Cell3
         &lt;/div&gt;&lt;/div&gt;&lt;div class="row"&gt;&lt;div class="cell"&gt;
            Row2-Cell1
         &lt;/div&gt;&lt;div class="cell"&gt;
            Row2-Cell2
         &lt;/div&gt;&lt;div class="cell"&gt;
            Row2-Cell3
         &lt;/div&gt;&lt;/div&gt;&lt;div class="row"&gt;&lt;div class="cell"&gt;
            Row3-Cell1
         &lt;/div&gt;&lt;div class="cell"&gt;
            Row3-Cell2
         &lt;/div&gt;&lt;div class="cell"&gt;
            Row3-Cell3
         &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS display Property with none Value

    The following example illustrates the use of none value on div elements to hide the element.

    Example

    <!DOCTYPE html><html><head><style>
    
      .hidden {
         display: none;
      }
      .visible {
         background-color: #4CAF50;
         color: white;
         padding: 10px;
         margin: 10px;
      }
    </style></head><body><h2>
      CSS display property
    </h2><h4>display: none</h4><div class="visible">
      This is visible
    </div><div class="hidden">
      This is hidden
    </div><div class="visible">
      This is also visible
    </div></body></html>
  • Hover Effects

    CSS hover effects are used to make interactive elements such as buttons and links more interactive. The :hover pseudo-class in CSS is used to target an element when the user hovers over it with the mouse cursor. Its purpose is to apply styles to improve the user experience.

    The :hover property can be used in various scenarios such as to change the button color when we hover it, adjust the size of div boxes, or show the hidden content.

    Hover over me!

    What is Hover Pseudo-Class?

    • In CSS, the pseudo-class :hover is a type of selector used to target and style an element when a user moves the mouse pointer over the element.
    • Hover effects are mostly used with interactive elements like buttons, links, etc to provide the user with a dynamic experience.
    • Hover effects are useful to add a dynamic and engaging look to a website.

    Background Change on Hover CSS

    You can use the :hover property to change the background of any element by hovering over it.

    Example

    In this example, we have used the background-color property with :hover pseudo class to change the background color of the div container when hovered over it.

    <!DOCTYPE html><html><head><style>
    
        .main{
            display: flex;
            justify-content: space-around;
        }
        .container{
            width: 40%; 
            height: 100px; 
            background-color: #D5E8D4; 
            border: 2px solid black; 
            padding: 10px;
            justify-content: center;
            align-items: center;
            display: flex;
        }
        .container:hover{
            background-color: #33FF33;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS :hover pseudo class&lt;/h2&gt;&lt;div class="main"&gt;&lt;div class="container"&gt; Hover over me! &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Display Hidden Text with CSS hover

    To display any hidden text or content with CSS, you can use the :hover pseudo-class. Here is an example to display the hidden text on hover.

    Example

    In this example, we have used the opacity property with the :hover pseudo-class to display the hidden text upon hovering over the div element.

    <!DOCTYPE html><html><head><style>
    
        .container {
            width: 200px;
            height: 30px;
            padding: 10px 20px;
            margin: 10px;
            font-size: 16px;
            font-weight: bold;
            border: 2px solid #04af2f;
            border-radius: 10px;
            text-align: center;
            line-height: 30px;            
        }
        .hide {
            opacity: 0;   
            transition: opacity 0.3s;         
        }
        .container:hover .hide {
            opacity: 1;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS :hover pseudo-class&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Hover over the box below to reveal the hidden message inside.&lt;/strong&gt;&lt;/p&gt;&lt;div class="container"&gt;&lt;div class="hide"&gt;April Fool :)&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Button Scale Effect on Hover

    You can style a button by hovering over it to make the web page more interactive. You can add transformation properties, transition, animation, and many more to a button while hovering over it.

    Example

    In this example, we have used the text-transform property to the button that scales the size of the button using the scale() function on hovering over it.

    <!DOCTYPE html><html><head><style>
    
        button {
            padding: 10px 20px;
            margin: 10px;
            background-color: #ffffff;
            color: #228B22;
            border: 2px solid #228B22;
            border-radius: 5px;
            text-decoration: none;
            font-size: 16px;
            font-weight: bold;
            transition: transform 0.3s;
        }
        button:hover {
            transform: scale(1.2);
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS :hover pseudo class&lt;/h2&gt;&lt;button&gt;Hover over me!&lt;/button&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Border with Hover Effect

    To set a border with the hover effect, we use the border property with :hover property. You can set the border properties such as color, width, style, and radius of the border.

    Example

    In this example, we have added a border to the div element when we hover the div element.

    <!DOCTYPE html><html><head><style>
    
        div {
            width: fit-content;
            padding: 10px 20px;
            margin: 10px;
            font-size: 16px;
            font-weight: bold;
            transition: border 0.1s, border-radius 0.1s;
        }
        div:hover {
            border: 2px solid #228B22;
            border-radius: 10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS :hover pseudo class&lt;/h2&gt;&lt;div&gt; Hover me!!! &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS hover Effect with Box Shadow

    You can add shadow to any HTML element when hovering over that element. Here is an example of adding a shadow to the div element.

    Example

    The following example uses the box-shadow property with :hover property to add a shadow to the div box when we hover over it.

    <!DOCTYPE html><html><head><style>
    
        div {
            width: fit-content;
            padding: 10px 20px;
            margin: 10px;
            font-size: 16px;
            font-weight: bold;
            transition: box-shadow 0.1s;
            border: 2px solid #228B22;
            border-radius: 10px;
        }
        div:hover {
            box-shadow: 20px 20px 10px grey;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS :hover pseudo class&lt;/h2&gt;&lt;div&gt; Hover me!!! &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Glow Effect on Hover

    You can add glowing effects to HTML elements using CSS properties such as linear-gradient, background-color, animation, and many more. Here is an example of how you can add the glowing effect to a button.

    Example

    In this example, we have used the linear-gradient function with :hover property to add a glowing effect to the button when we hover over it.

    <!DOCTYPE html><html><head><style>
    
        body {
            height: 300px;
            overflow: hidden;
            display: grid;
            justify-content: center;
            align-items: center;
        }
        .glow {
            padding: 10px;
            width: 250px;
            height: 50px;
            border: none;
            outline: none;
            color: #fff;
            background: #111;
            cursor: pointer;
            position: relative;
            z-index: 0;
            border-radius: 20px;
        }
        .glow:before {
            content: '';
            background: linear-gradient(60deg, #ff0000, #ff7300, 
                                #fffb00, #48ff00, #00ffd5, #002bff, 
                                #7a00ff, #ff00c8, #ff0000);
            position: absolute;
            top: -4px;
            left:-4px;
            background-size: 400%;
            z-index: -1;
            filter: blur(15px);
            width: calc(100% + 6px);
            height: calc(100% + 6px);
            animation: glowing 20s linear infinite;
            opacity: 0;
            transition: opacity .3s ease-in-out;
            border-radius: 10px;
        }
        .glow:active {
            color: rgb(246, 235, 235)
        }
        .glow:active:after {
            background: transparent;
        }
        .glow:hover:before {
            opacity: 1;
        }
        .glow:after {
            z-index: -1;
            content: '';
            position: absolute;
            width: 100%;
            height: 100%;
            background: #111;
            left: 0;
            top: 0;
            border-radius: 10px;
        }
        @keyframes glowing {
            0% { 
                background-position: 0 0; 
            }
            50% { 
                background-position: 400% 0; 
            }
            100% { 
                background-position: 0 0; 
            }
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;button class="glow" type="button"&gt;
        HOVER OVER &amp; CLICK!
    &lt;/button&gt;&lt;/body&gt;&lt;/html&gt;</pre>
  • hyphens Property

    The hyphens Property

    The CSS hyphens property controls how words are broken into lines when text is too long to fit on a single line. It improves the readability of text that wraps across multiple lines. The property only applies to block-level elements.

    Syntax

    The syntax for the hyphens property is as follows:

    hyphens: none | manual | auto | initial | inherit;

    Property Values

    ValueDescription
    noneIt disables the hyphenation.
    manualIt is the default value that specifies manual hyphenation behavior for text at &hyphen or &shy.
    autoIt allows hyphenation at appropriate hyphenation points, as determined by the browser.
    initialThis sets the property to its default value.
    inheritThis inherits the property from the parent element.

    Prevent Hyphenation with hyphens: none in CSS

    To prevent the hyphenation of words, we use the none value. The words will not be broken into lines, even if they are too long to fit on a single line.

    Example

    In this example, we have used hyphens: none; to prevent automatic hyphenation of words.

    <!DOCTYPE html><html><head><style>
    
      .container {
         border: 2px solid #12782f;
         background-color: coral;
         width: 70px;
         padding: 10px;
      }
      .hyphenated-none {
         hyphens: none;
      }
    </style></head><body><h2>
      CSS hyphens property
    </h2><h4>
      hyphens: none
    </h4><div class="container"><p class="hyphenated-none">
         This is a much­much­much larger building.
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Manual Hyphenation with hyphens: manual in CSS

    To allow hyphenation only at points where we have explicitly inserted hyphens using &hyphen or &shy, we use the manual value. This is a default value.

    Example

    In this example, we have used the hyphens: manual, to allow hyphenation only where we have manually inserted using soft hyphens (­).

    <!DOCTYPE html><html><head><style>
    
      .container {
         border: 2px solid #12782f;
         background-color: coral;
         width: 70px;
         padding: 10px;
      }
      .hyphenated-none {
         hyphens: manual;
      }
    </style></head><body><h2>
      CSS hyphens property
    </h2><h4>
      hyphens: manual
    </h4><div class="container"><p class="hyphenated-none">
         This is a much­much­much larger building.
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Automatic Hyphenation with hyphens:auto in CSS

    To let the browser automatically hyphenate words at points that are considered to be appropriate, according to the language's hyphenation rules, we use the auto value.

    Example

    Here is an example using hyphens: auto value.

    <!DOCTYPE html><html><head><style>
    
      .container {
         border: 2px solid #12782f;
         background-color: coral;
         width: 70px;
         padding: 10px;
      }
      .hyphenated-none {
         hyphens: auto;
      }
    </style></head><body><h2>
      CSS hyphens property
    </h2><h4>
      hyphens: auto
    </h4><div class="container"><p class="hyphenated-none">
         This is a much­much­much larger building.
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>
  • position Property

    The position Property

    CSS position property specifies the position of an element in a web page. CSS properties such as topbottomright, and left are used to control the exact position of an element in the web page.

    The position property can be used to create floating elements, a floating sidebar, and other interactive features.

    Syntax

    The syntax for the CSS position property is as follows:

    position: static | relative | absolute | fixed | sticky;

    Possible Values

    ValueDescription
    staticIt is the default value where the element is positioned according to the normal flow of the page. So, if we set left/right/top/bottom/z-index, then there will be no effect on that element.
    relativeThe element’s original position is according to the normal flow of the page just like static value. But now the left/right/top/bottom/z-index will work.
    absoluteThe element is completely removed from the document flow. It is then positioned with respect to its nearest positioned ancestor element. The positioned element should be any value except static.
    fixedThe element’s fixed positioning is just like absolute positioning, except the containing block of a fixed element is always the viewport. Here the element is totally removed from the document’s flow and does not have a position relative to any part of the document.
    stickyThe element sticks to the top of its nearest positioned ancestor that has a “scrolling mechanism”. It behaves as relative till it reaches the scrolling position, then behaves as fixed.

    Applies To

    The position property can be applied to all elements.

    CSS position Property with static Value

    The position property for the div element in this example is set to static. The left, right, top, and bottom properties will have no effect on the div element.

    Example

    The following example sets the position property of the div element to static.

    <html><head><style>
       .container {
    
      display: inline-block;
      background-color: #f2c3ee;
      border: 1px solid #000000;
      padding: 10px;
      margin-bottom: 20px;
      width: 300px;
      height: 100px;
    } .box {
      display: inline-block;
      position: static;
      background-color: #bbedbb;
      border: 1px solid #000000;
      padding: 10px;
      width: 300px;
      height: 100px;
    } </style></head><body><div class="container"><h2>Normal Box</h2><p>This is a normal box.</p></div><div class="box"><h2>Position: static</h2><p>This is a box with static position.</p></div></body></html>

    CSS position Property with relative Value

    The following example sets the position property of the div element to relative. This allows you to set the top, bottom, left, and right positioning of the div element.

    Example

    In this example, we have used position: relative; to set the positioning of the child element to relative.

    <html ><head><style>
       .container {
    
      background-color: #f2c3ee;
      border: 1px solid #333;
      padding: 10px;
      margin-bottom: 20px;
      width: 350px;
      height: 300px;
    } .box {
      background-color: #bbedbb;
      border: 1px solid #333;
      padding: 10px;
      position: relative;
      width: 300px;
      height: 100px;
      left: 20px;
      top: 20px;
    } </style></head><body><div class="container"><h2>Normal Box</h2><p>This is a Normal box.</p><div class="box"><h2>Position: Absolute</h2><p>This is a box with absolute position.</p></div></div></body></html>

    CSS position Property with absolute Value

    You can use absolute value to set the position of an element relative to its nearest ancestor element.

    Example

    In this example, we have used position: absolute; to position the child element relative to its nearest positioned container.

    <html ><head><style>
       .container {
    
      background-color: #f2c3ee;
      border: 1px solid #333;
      padding: 10px;
      margin-bottom: 20px;
      width: 350px;
      height: 100px;
    } .box {
      background-color: #bbedbb;
      border: 1px solid #333;
      padding: 10px;
      position: relative;
      width: 300px;
      height: 100px;
      left: 20px;
      bottom: 20px;
    } </style></head><body><div class="container"><h2>Normal Box</h2><p>This is a Normal box.</p><div class="box"><h2>Position: Absolute</h2><p>This is a box with absolute position.</p></div></div></body></html>

    CSS position Property with fixed Value

    To make an element stay in the same place on the screen even when the user scrolls, you can set the position property to fixed. You can then use the left, right, top, and bottom properties to position the element where you want it.

    Example

    In this example, we have used position: fixed; to create a fixed position of paragraph on the div.

    <html><head><style>
       .container {
    
      width: 400px;
      height: 200px;
      background-color: #f2c3ee;
      overflow: auto;
      padding: 5px;
    } .box {
      position: fixed;
      top: 15px;
      left: 60px;
      padding: 5px;
      background-color: #bbedbb;
      text-align: center;
    } </style></head><body><div class="container"><p>This CSS tutorial covers everything from basic styling concepts and selectors to advanced techniques, such as flexbox, grid, animations, and CSS variables. This CSS tutorial is designed to help both beginners and experienced designers to make them masters in creating visually appealing, responsive, and modern web designs.</p><p class="box">Tutorials point CSS Position Fixed</p><p>CSS is the acronym for "Cascading Style Sheet". It's a style sheet language used for describing the presentation of a document written in a markup language like HTML. CSS helps the web developers to control the layout and other visual aspects of the web pages. CSS plays a crucial role in modern web development by providing the tools necessary to create visually appealing, accessible, and responsive websites.</p></div></body></html>

    CSS position Property with sticky Value

    You can set the position property to sticky to create an element that sticks to the top of the viewport when the user scrolls through a page. It is a combination of the position: relative and position: fixed properties.

    Example

    In this example, we have applied position: sticky; on a paragraph element that scrolls until a specified position then sticks at one place.

    <html><head><style>
       .container {
    
      width: 400px;
      height: 200px;
      background-color: #f2c3ee;
      overflow: auto;
      padding: 5px;
    } .box {
      position: sticky;
      top: 15px;
      padding: 5px;
      background-color: #bbedbb;
      text-align: center;
    } </style></head><body><div class="container"><p>This CSS tutorial covers everything from basic styling concepts and selectors to advanced techniques, such as flexbox, grid, animations, and CSS variables. This CSS tutorial is designed to help both beginners and experienced designers to make them masters in creating visually appealing, responsive, and modern web designs.</p><p class="box">Tutorials point CSS Position Sticky</p><p>CSS is the acronym for "Cascading Style Sheet". It's a style sheet language used for describing the presentation of a document written in a markup language like HTML. CSS helps the web developers to control the layout and other visual aspects of the web pages. CSS plays a crucial role in modern web development by providing the tools necessary to create visually appealing, accessible, and responsive websites.</p><p>Each version of CSS builds upon the previous ones, adding new features and refining existing capabilities to meet the evolving needs of web developers and designers. CSS is referred as just CSS now, without a version number.</p></div></body></html>

    Positioning Text In an Image Using CSS

    To position the text in different directions, you can use the position: absolute property.

    Example

    In this example, we have used the absolute value to position the text elements in different directions on the image. The text elements are positioned at the center, top left, top right, bottom left, and bottom right corners.

    <html><head><style>
       .container {
    
      position: relative;
      border: 2px solid #ef2c2c;
    } .center {
      position: absolute;
      top: 45%;
      width: 100%;
      text-align: center;
    } .top-left {
      position: absolute;
      top: 12px;
      left: 30px;
    } .top-right {
      position: absolute;
      top: 12px;
      right: 30px;
    } .bottom-left {
      position: absolute;
      bottom: 12px;
      left: 30px;
    } .bottom-right {
      position: absolute;
      bottom: 12px;
      right: 30px;
    } img {
      width: 100%;
      opacity: 0.3;
    } </style></head><body><div class="container"><img src="/css/images/pink-flower.jpg" alt="Pink flower" width="1000px" height="350px"><h3 class="center">Text at Centered</h3><h3 class="top-left">Text at Top Left</h3><h3 class="top-right">Text at Top Right</h3><h3 class="bottom-left">Text at Bottom Left</h3><h3 class="bottom-right">Text at Bottom Right</h3></div></body></html>

    CSS Position – Related Properties

    Following is the list of all the CSS properties related to the position:

    PropertyDescription
    bottomUsed with the position property to place the bottom edge of an element.
    clipSets the clipping mask for an element.
    leftUsed with the position property to place the left edge of an element.
    overflowDetermines how overflow content is rendered.
    positionSets the positioning model for an element.
    rightUsed with the position property to place the right edge of an element.
    topSets the positioning model for an element.
    vertical-alignSets the vertical positioning of an element.
    z-indexSets the rendering layer for the current element.
  • order Property

    CSS order property is used to specify the order in which flex items appear within a flex container. The order of the flex items is determined by the values of their order property. The flex items with the lower order value will be displayed first.

    Syntax

    order: number | initial | inherit;

    Property Values

    ValueDescription
    numberOrder of flex items is specified using numeric values – positive or negative values. With positive values, the element with smaller positive value appears first. With negative values, the element with larger negative value appears first.
    initialIt sets the property to its default value.
    inheritIt inherits the property from the parent element.

    Examples of CSS Order Property

    The following examples explain the order property with different elements.

    Order Property with Positive Numeric Values

    The order of the flex-items can be set by specifying positive numeric values to the order property. With positive values, the element will smaller value appears first. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .container {
         height: 150px;
         display: flex;
         gap: 4px;
      }
      .container&gt;div {
         padding: 10px;
         text-align: center;
         height: 70px;
         width: 70px;
      }
      .box1 {
         background-color: lightgreen;
         order: 2;
      }
      .box2 {
         background-color: lightblue;
         order: 4;
      }
      .box3 {
         background-color: lightcoral;
         order: 1;
      }
      .box4 {
         background-color: lightgray;
         order: 3;
      }
    </style></head><body><h2>
      CSS order property
    </h2><h4>
      order: 2-4-1-3 (first element- second position, 
      second element- fourth position, third element- 
      first position, fourth element- third position)
    </h4><div class="container"><div class="box1">
         One
      &lt;/div&gt;&lt;div class="box2"&gt;
         Two
      &lt;/div&gt;&lt;div class="box3"&gt;
         Three
      &lt;/div&gt;&lt;div class="box4"&gt;
         Four
      &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Order Property with Negative Numeric Values

    The order of the flex-items can be set by specifying negative numeric values to the order property. With negative values, the element will larger value appears first. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .container {
         height: 150px;
         display: flex;
         gap: 4px;
      }
      .container &gt; div {
         padding: 10px;
         text-align: center;
         height: 70px;
         width: 70px;
      }
      .box1 {
         background-color: lightgreen;
         order: -2;
      }
      .box2 {
         background-color: lightblue;
         order: -1;
      }
      .box3 {
         background-color: lightcoral;
         order: -3;
      }
      .box4 {
         background-color: lightgray;
         order: -4;
      }
    </style></head><body><h2>
      CSS order property
    </h2><h4>
      order: -2 / -1 / -3 / -4 (first element- third position, 
      second element- fourth position, third element- second 
      position, fourth element- first position)
    </h4><div class="container"><div class="box1">
         One
      &lt;/div&gt;&lt;div class="box2"&gt;
         Two
      &lt;/div&gt;&lt;div class="box3"&gt;
         Three
      &lt;/div&gt;&lt;div class="box4"&gt;
         Four
      &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Order Property with Images

    The order property can also be used with images as flex-items. The positions of the images depend on the values provided - positive or negative. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .container {
         height: 150px;
         display: flex;
         gap: 4px;
      }
      .container&gt;img {
         height: 100px;
         width: 100px;
      }
      .img1 {
         background-color: lightgreen;
         order: 4;
      }
      .img2 {
         background-color: lightblue;
         order: 2;
      }
      .img3 {
         background-color: lightcoral;
         order: 1;
      }
      .img4 {
         background-color: lightgray;
         order: 3;
      }
    </style></head><body><h2>
      CSS order property
    </h2><h4>
      order: 4-2-1-3 (first image- fourth position, 
      second image- second position, third image - 
      first position, fourth image - third position)
    </h4><div class="container"><img src="/css/images/red-flower.jpg"
      alt="flower" class="img1" /&gt;&lt;img src="/css/images/orange-flower.jpg" 
      alt="flower" class="img2" /&gt;&lt;img src="/css/images/white-flower.jpg" 
      alt="flower" class="img3" /&gt;&lt;img src="/css/images/pink-flower.jpg" 
      alt="flower" class="img4" /&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>