Author: saqibkhan

  •  2D Transforms

    CSS transforms are used to modify the element’s shape and sizes and are responsible for movements of elements in two-dimensional space using functions like translate(), scale(), rotate(), and skew(). These functions allow you to move, scale, rotate, and skew elements along the X and Y axes, creating various visual effects and manipulations.

    2D Transform

    3D Transform

    Table of Contents

    CSS 2D Translate

    CSS translate() function moves an element along the X and Y axes.

    Example

    The following example shows a box that moves along these axes when hovered over.

    Open Compiler

    <!DOCTYPE html><html lang="en"><head><style>
    
        body {
            height: 300px;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f0f0f0;
            font-family: Arial, sans-serif;
        }
        /* The Box Element */
        .box {
            width: 200px;
            height: 200px;
            background-color: #4CAF50;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 1.5em;
            border-radius: 10px;
            /* Initial 2D Translation */
            transform: translate(50px, 50px);
            transition: transform 0.6s ease;
        }
        /* Hover State with Different 2D Translation */
        .box:hover {
            transform: translate(-50px, -50px);
            background-color: #2ecc71;
            cursor: pointer;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="box"&gt;
        2D Box
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS 2D Rotate

    CSS rotate() function rotates an element around a specified point on the 2D plane.

    Example

    The following example shows a box that rotates when hovered over, creating a dynamic effect.

    Open Compiler

    <!DOCTYPE html><html lang="en"><head><style>
    
        body {
            height: 300px;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f0f0f0;
            font-family: Arial, sans-serif;
        }
        /* The Box Element */
        .box {
            width: 200px;
            height: 200px;
            background-color: #4CAF50;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 1.5em;
            border-radius: 10px;
            /* Initial 2D Rotation */
            transform: rotate(15deg);
            transition: transform 0.6s ease;
        }
        /* Hover State with Different 2D Rotation */
        .box:hover {
            transform: rotate(-15deg);
            background-color: #2ecc71;
            cursor: pointer;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="box"&gt;
        2D Box
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS 2D Scale

    CSS scale() function scales an element along the X and Y axes.

    Example

    The following example shows a box that scales up and down when hovered over, creating a zoom effect.

    Open Compiler

    <!DOCTYPE html><html lang="en"><head><style>
    
        body {
            height: 300px;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f0f0f0;
            font-family: Arial, sans-serif;
        }
        /* The Box Element */
        .box {
            width: 150px;
            height: 150px;
            background-color: #4CAF50;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 1.5em;
            border-radius: 10px;
            /* Initial 2D Scaling */
            transform: scale(1);
            transition: transform 0.6s ease;
        }
        /* Hover State with Different 2D Scaling */
        .box:hover {
            transform: scale(1.5);
            background-color: #2ecc71;
            cursor: pointer;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="box"&gt;
        2D Box
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS 2D Skew

    CSS skew() function skews an element along the X and Y axes.

    Example

    The following example shows a box that skews when hovered over, creating a slanted effect.

    Open Compiler

    <!DOCTYPE html><html lang="en"><head><style>
    
        body {
            height: 300px;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f0f0f0;
            font-family: Arial, sans-serif;
        }
        /* The Box Element */
        .box {
            width: 200px;
            height: 200px;
            background-color: #4CAF50;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 1.5em;
            border-radius: 10px;
            /* Initial 2D Skew */
            transform: skewX(10deg) skewY(10deg);
            transition: transform 0.6s ease;
        }
        /* Hover State with Different 2D Skew */
        .box:hover {
            transform: skewX(-10deg) skewY(-10deg);
            background-color: #2ecc71;
            cursor: pointer;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="box"&gt;
        2D Box
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>
  • Styling Text

    CSS Styling Text involves modifying the appearance of text content by setting proper color, alignment, letter-spacing, and indention to make it more visually appealing. This chapter demonstrates how to style texts on web pages using CSS properties.

    How to Style Text in CSS?

    We can style text in the following ways to style texts in CSS.

    • Change Color: The default color of text on a webpage will be black. You can change this according to your webpage theme, using the color property in CSS.
    • Set Alignment: You can use the text-align property in CSS to specify the alignment (center, left, right) of text inside a container.
    • Text Decoration: The text-decoration property in CSS can be used to add effects like underline, overline, or strike-through to texts.
    • Shadow Effect: If you want to create a shadow around text in your webpage you can use text-shadow property in CSS. This can create a 3D effect or a subtle glow around the text.
    • Change Font Style: The font-style property allows you to style the text as normal, italic, or oblique.

    Properties for Styling Text

    The following table lists CSS properties for styling text:

    PropertyDescription
    colorSets the color of the text.
    text-alignSets the alignment of the text.
    text-align-lastSets the alignment of the last line of a block of text.
    directionSets the direction of the text.
    text-indentSets the indentation of the first line of the text.
    letter-spacingSpecifies the space between the letters of a word.
    word-spacingSpecifies the space between the words in a block of text.
    white-spaceControls the white space flow inside the text in an element.
    text-decorationA shorthand property for setting the text decoration.
    text-decoration-lineIt specifies the type of line the text decoration will have.
    text-decoration-styleIt specifies the type of line drawn as a text decoration such as solid, wavy, dotted, dashed, or double.
    text-decoration-colorIt sets the color of the text-decoration line.
    text-decoration-thicknessIt sets the thickness of the text-decoration line.
    text-justifyIt controls how spaces are distributed between words and characters to align text.
    text-transformTransforms the text in either uppercase, lowercase, or capitalize.
    line-heightIt controls the amount of space between lines of text within an element.
    text-emphasisApplied emphasis marks to text.
    text-shadowAdds shadow to the text.
    line-breakControls how to set the rule for a line break.
    word-breakControls how to set the rule for a word break.
    text-combine-uprightCombines multiple typographic character units into the space of a single typographic character unit.
    text-orientationSets the orientation of the text characters in a line.
    text-underline-offsetAdds special visual effects to the text.
    text-overflowControls how hidden overflow content is displayed to users.

    Setting Text Color in CSS

    To set the text color, you can use the color property. The color can be specified with color name, Hexadecimal value, rgb/rgba value, or hsl/hsla value.

    Example

    In this example, we have set the text color of paragraphs using the color property.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        .name {
            color: blueviolet;
        }
        .hex {
            color:#ff00ff;
        }
        .rgb {
            color: rgb(255,124,100);
        }
        .rgba {
            color: rgb(255,124,100,0.5);
        }
        .hsl {
            color: hsl(7deg, 98%, 50%);
        }
        .hsla {
            color: hsl(7deg, 98%, 50%, 0.5);
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p class="name"&gt;
        Color Name: blueviolet;
    &lt;/p&gt;&lt;p class="hex"&gt;
        Hexadecimal value: #ff00ff;
    &lt;/p&gt;&lt;p class="rgb"&gt;
        RGB value: rgb(255, 124, 100);
    &lt;/p&gt;&lt;p class="rgba"&gt;
        RGBA value: rgba(255, 124, 100, 0.5);
    &lt;/p&gt;&lt;p class="hsl"&gt;
        HSL value: hsla(7deg, 98%, 50%);
    &lt;/p&gt;&lt;p class="hsla"&gt;
        HSLA value: hsla(7deg, 98%, 50%, 0.5);
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting Text Alignment

    The text in a webpage can be aligned horizontally and vertically inside a container. To set the alignment of the text, we use the following CSS properties.

    • The text-align property specifies the horizontal alignment of text in a container (left, right, center, justify).
    • The vertical-align property is used to align the text vertically at the top, bottom, baseline, and middle. This property is used with inline elements, inline-block elements, and table cells.

    Example

    In this example, we have used text-align and vertical-align properties to set the horizontal and vertical alignment of the text.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        th{
            vertical-align: bottom;
            border: 2px solid; 
            width: 200px; 
            height: 150px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Text Alignment&lt;/h2&gt;&lt;p style="text-align: left;"&gt;Text Left Alignment.&lt;/p&gt;&lt;p style="text-align: right;"&gt;Text Right Alignment.&lt;/p&gt;&lt;p style="text-align: center;"&gt;Text Center Alignment.&lt;/p&gt;&lt;table&gt;&lt;th&gt;This is vertical alignment&lt;/th&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Aligning the Last Line in CSS

    To set the alignment for the last line of a block of text, you can use the text-align-last property. It is useful when text-align: justify; is used to align the last line properly.

    Example

    In this example, we have used the text-align-last property to align the last line differently.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        p {
            width: 300px;
            text-align: justify;
            text-align-last: right;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;text-align-last property&lt;/h2&gt;&lt;p&gt;This is an example of text alignment. The last line of this paragraph will be aligned differently than the rest of the text.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Aligning Text with text-justify

    The text-justify property specifies the justification method of text when text-align: justify; is applied. The text remains unaffected in modern browsers. Try running the code in Firefox.

    Example

    In this example, we have used the text-justify property to control text justification.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        p {
            width: 300px;
            text-align: justify;
            text-justify: inter-word;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;text-justify property&lt;/h2&gt;&lt;p&gt;This paragraph demonstrates how the text-justify property works. It adjusts the spacing between words.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting Text Direction in CSS

    The text direction refers to the orientation of text characters in a document or element. You can use the direction property to set the text direction. This property accepts two values which are as follows:

    • ltr (Left-to-Right): It is the default value, used for languages that are written from left to right, like English.
    • rtl (Right-to-Left): It is used for languages that are written from right to left, such as Arabic or Hebrew. When using rtl, the text will be aligned right by default.

    Additionally, CSS provides a shorthand property, unicode-bidi, to control the bidi algorithm, which specifies how characters with different writing directions are displayed when they appear in the same paragraph.

    Example

    In this example, we have used the direction property to set the text direction of paragraphs.

    Open Compiler

    <!DOCTYPE html><html><body><p style = "direction: rtl;">
    
        Right to Left
    &lt;/p&gt;&lt;p style = "direction: ltr;"&gt;
        Left to Right
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Applying Text Decoration in CSS

    You can use the text-decoration property for adding extra decoration to the text, such as adding a line (underline, strikethrough, overline), color, style, and thickness to the line.

    It is a shorthand property for text-decoration-linetext-decoration-styletext-decoration-color, and text-decoration-thickness.

    Syntax

    The syntax for the text-decoration property is as follows:

    text-decoration: text-decoration-line text-decoration-color text-decoration-style text-decoration-thickness | initial | inherit;

    Example

    In this example, we have used the text-decoration property to apply overline, line-through, and underline styles with different colors, thicknesses, and line types.

    Open Compiler

    <!DOCTYPE html><html><body><h2>Text Decoration</h2><p style="text-decoration: overline solid red 5px;">
    
        Overline text decoration.
    &lt;/p&gt;&lt;p style="text-decoration: line-through solid green 1px;"&gt;
        Line-through text decoration.
    &lt;/p&gt;&lt;p style="text-decoration: underline dashed 2pt blue;"&gt;
        Underline text decoration.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Using CSS text-transform for Text Styling

    To change the appearance of text, the text-transform property is used. It transforms the text in various ways such as converting the text to uppercase, or lowercase, capitalizing the first letter of each word, or even capitalizing all letters.

    Example

    In this example, we have used the text-transform property to transform the text to uppercase, lowercase, and capitalize.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        p{
            font-family: arial, sans-serif;
            font-size: 1em;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Text Transform&lt;/h2&gt;&lt;p style="text-transform: capitalize;"&gt;
        capitalizes the first character of each word.
    &lt;/p&gt;&lt;p style="text-transform: uppercase;"&gt;
        Transforms all text to uppercase.
    &lt;/p&gt;&lt;p style="text-transform: lowercase;"&gt;
        Transforms all text to Lowercase.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Adding Text Emphasis in CSS

    To apply emphasis marks on a block of text, you can use the text-emphasis property. These marks are typically used to highlight specific content or to indicate pronunciation or stress in certain languages.

    It is a shorthand property for text-emphasis-style and text-emphasis-color.

    Example

    In this example, we have used the text-emphasis property to apply emphasis marks to the text.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        p{
            font-family: arial, sans-serif;
            font-size: 1em;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Text Emphasis&lt;/h2&gt;&lt;p style="text-emphasis: dot;"&gt; 
            The text is emphasized using dot.
        &lt;/p&gt;&lt;p style="text-emphasis: circle red;"&gt;
            The text is emphasized using red circle.
        &lt;/p&gt;&lt;p style="text-emphasis: triangle;"&gt; 
            The text is emphasized using triangle.
        &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Text Indentation Property

    To add space between the margin and the first line of text, you can use the text-indent property. A proper indentation improves the readability and clarity of text on a page.

    Example

    In this example, we have used the text-indent property to indent the first line of the text of the paragraphs.

    Open Compiler

    <html><body><h2>Text indentation</h2><p style="text-indent: 2cm;">Text indentation: 2 cm.</p><p style="text-indent: 2in;">Text indentation: 2 inches.</p><p style="text-indent: 20%;">Text indentation: 20%.</p></body></html>

    Letter Spacing in CSS

    To adjust the space between the letters of a text, you can use the letter-spacing property. The space can be increased or decreased between the letters.

    Example

    In this example, we have used the letter-spacing property to increase and decrease the space between the letters of the text.

    Open Compiler

    <!DOCTYPE html><html><body><h2>Letter spacing</h2><p style="letter-spacing: normal;">
    
        Letter spacing normal.
    &lt;/p&gt;&lt;p style="letter-spacing: 5px;"&gt;
        Letter spacing increased.
    &lt;/p&gt;&lt;p style="letter-spacing: -1px;"&gt;
        Letter spacing decreased.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Applying word-spacing in CSS

    The word-spacing property is used to adjust the space between the words of a text. The space can be increased or decreased between the words.

    Example

    In this example, we have used the word-spacing property to increase and decrease the space between the words of the text.

    Open Compiler

    <!DOCTYPE html><html><body><h2>Word spacing</h2><p style="word-spacing: normal;">
    
        Word spacing normal.
    &lt;/p&gt;&lt;p style="word-spacing: 100px;"&gt;
        Word spacing increased.
    &lt;/p&gt;&lt;p style="word-spacing: -2px;"&gt;
        Word spacing decreased.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Wrapping Text with white-space Property

    The white-space property controls how you can handle the white space inside an element. It allows you to manage the handling of spaces, tabs, and line breaks in the text.

    Example

    Here is an example of the white-space property using different values to control the white space inside the text.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        p{
            border: 2px solid;
            padding: 5px;
            width: 50%;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;White-space property&lt;/h2&gt;&lt;p style="white-space: normal;"&gt;
        This is a paragraph with the white-space property set 
        to normal. The text will wrap when necessary, and 
        extra    spaces and line breaks are    ignored.
    &lt;/p&gt;&lt;p style="white-space: nowrap;"&gt;
        This is a paragraph with the white-space property set
        to nowrap. The text will not wrap to the next line, even 
        if it overflows the container.
    &lt;/p&gt;&lt;p style="white-space: pre;"&gt;
        This is a paragraph with white-space property set to pre.
        The text will respect all   spaces and line breaks. Means,
        the   text will be displayed as it is in     HTML code.
    &lt;/p&gt;&lt;p style="white-space: pre-wrap;"&gt;
        This is a paragraph with the white-space property set to
        pre-wrap. The text will respect all spaces and line breaks,
        but will wrap when necessary.
    &lt;/p&gt;&lt;p style="white-space: pre-line;"&gt;
        This is a paragraph with the white-space property set 
        to pre-line. The text will collapse spaces and wrap when 
        necessary, but will respect line breaks.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Line-Break Property

    To control how line breaks are handled in text, we use the CSS line-break property. This property is useful for handling line breaks in languages like Japanese, Chinese, or Korean. You can use values such as auto, loose, normal, strict, and anywhere with this property.

    Example

    In this example, we have used the line-break property with different values to control how the text breaks across lines based on language rules.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        p{
            border: 2px solid;
            padding: 5px;
            width: 50%;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Line-break property&lt;/h2&gt;&lt;p style="line-break: auto;"&gt;
        This paragraph uses the line-break property set to auto.
        Line breaking is determined based on the default rules.
    &lt;/p&gt;&lt;p style="line-break: loose;"&gt;
        This paragraph uses the line-break property set to loose.
        Line breaking is done more frequently, typically used in 
        CJK (Chinese, Japanese, Korean) text.
    &lt;/p&gt;&lt;p style="line-break: normal;"&gt;
        This paragraph uses the line-break property set to normal.
        Line breaking follows the standard rules for the language 
        being used.
    &lt;/p&gt;&lt;p style="line-break: strict;"&gt;
        This paragraph uses the line-break property set to strict.
        Line breaking is restricted, typically preventing breaks 
        between characters that are normally kept together.
    &lt;/p&gt;&lt;p style="line-break: anywhere;"&gt;
        This paragraph uses the line-break property set to anywhere.
        Line breaks can happen at any point, even if it means 
        breaking words in unconventional places.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Word-Break Property

    The word-break property controls the behavior of word breaking and word wrapping in text. It handles the words when they are too long to fit within their container. You can use values such as normal, break-all, keep-all, and break-word with this property.

    Example

    In this example, we have used the word-break property with different values to control how the word breaks to fit their container.

    Open Compiler

    <!DOCTYPE html><html><body><h2>Word-break property</h2><p style="word-break: normal;">
    
        This paragraph uses the word-break property set to &lt;strong&gt;normal&lt;/strong&gt;. 
        Words will break only at normal word boundaries (such as 
        spaces or hyphens).
    &lt;/p&gt;&lt;p style="word-break: break-all;"&gt;
        This paragraph uses the word-break property set to &lt;strong&gt;break-all&lt;/strong&gt;.
        Words will break at any character to prevent overflow, 
        even in the middle of a word.
    &lt;/p&gt;&lt;p style="word-break: keep-all;"&gt;
        This paragraph uses the word-break property set to &lt;strong&gt;keep-all&lt;/strong&gt;.
        Words will only break at normal word boundaries, but CJK text 
        characters will not break unless necessary.
    &lt;/p&gt;&lt;p style="word-break: break-word;"&gt;
        This paragraph uses the word-break property set to &lt;strong&gt;break-word&lt;/strong&gt;.
        Words will break at normal boundaries or wherever necessary 
        to prevent overflow.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS line-height Property

    To specify the height of a line of a text, you can use the CSS line-height property . It controls the spacing between lines.

    Example

    In this example, we have used the line-height property to increase the space between lines.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        p {
            width: 300px;
            line-height: 2;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;line-height property&lt;/h2&gt;&lt;p&gt;This paragraph has a line height of 2, making the text more readable and spaced out.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Creating Text Shadows with CSS

    The text-shadow property is used to add a shadow effect to the text. It allows you to create a shadow behind the text by specifying the shadow's horizontal and vertical offsets, blur radius, and color.

    You can apply multiple shadows by separating each shadow with a comma. The order of the shadows matters, with the first shadow being closest to the text.

    Example

    In this example, we have used the text-shadow property to apply different shadow effects to the paragraphs, including single and multiple shadows with different offsets, colors, and blur radii.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        .txt1 {
            text-shadow: 2px 2px 5px grey;
        }
        .txt2 {
            text-shadow: -2px -2px 3px red;
        }
        .txt3 {
            text-shadow: 3px 3px 0px blue, -3px -3px 0px yellow;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Text-shadow property&lt;/h2&gt;&lt;p class="txt1"&gt;
        This text has a grey shadow with a blur radius of 5px.
    &lt;/p&gt;&lt;p class="txt2"&gt;
        This text has a red shadow with a blur radius of 3px 
        and offset to the top-left.
    &lt;/p&gt;&lt;p class="txt3"&gt;
        This text has two shadows: a blue shadow offset to the 
        bottom-right and a yellow shadow offset to the top-left.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS text-orientation Property

    To control the text orientation in vertical writing modes, we use the text-orientation property.

    Example

    In this example, we have used the text-orientation property to rotate the text vertically.

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        p {
            writing-mode: vertical-rl;
            text-orientation: upright;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;text-orientation property&lt;/h2&gt;&lt;p&gt;This text is displayed in a vertical layout using text-orientation.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • text-shadow Property

    The text-shadow property is used to add a shadow effect to text. It allows you to specify the color, offset, blur-radius, and spread-radius of the shadow.

    Possible Values

    • <color>:
      • Sets the color of the shadow.
      • It is optional.
      • It can be specified either before or after the offset values.
      • Any value for color can be specified, such as, name, HEX or RGB value.
    • <offset-x><offset-y>:
      • Any length value, specifying the x and y values.
      • x value represents the shadow’s horizontal distance from text.
      • y value represents the shadow’s vertical distance from text.
      • If x and y values equal 0, the shadow appears behind the text.
    • <blur-radius>
      • Any length value, specifying the value of blur-radius.
      • It is optional.
      • To make the blur look bigger, you need to provide higher value.
      • If no value is passed, it is taken as 0.

    Applies to

    All the HTML elements.

    DOM Syntax

    object.style.textShadow = "5px 5px 3px red";
    
    • The first two (5px,5px) values specify the length of the shadow offset i.e the X-coordinate and the Y-coordinate.
    • The third value (3px) specifies the blur radius.
    • The last value (red) describes the color of the shadow.

    CSS text-shadow – Simple Shadow Effects

    Following is the example which demonstrates how to set the shadow around a text. This may not be supported by all the browsers −

    Open Compiler

    <html><head></head><body><h2>Text Shadow</h2><p style="text-shadow: 5px 5px 3px yellow;">Text shadow</p><p style="text-shadow: 10px 5px #00ffff;">Text shadow</p><p style="text-shadow: blue 0px 0px 2px">Text shadow</p><p style="text-shadow: rgb(26, 69, 105) 0px 0px 10px">Text shadow</p></body></html>

  • caret-color Property

    CSS caret-color property specifies the color of the cursor, which is the visible marker, also known as the text input cursor. It is used with input elements such as input forms, text boxes, textarea etc. which use the cursor and are editable.

    Syntax

    caret-color: auto | color | transparent | initial | inherit;

    Property Values

    ValueDescription
    autoThe browser uses the currentColor for the caret. Default.
    colorThe color of the caret can be specified in different formats (color names, hex, rgb etc.).
    transparentThe caret is not visible.
    initialIt sets the property to its default value.
    inheritIt inherits the property from the parent element.

    Examples of CSS Caret Color Property

    The following examples explain the caret-color property with different values.

    Caret Color Property with Auto Value

    To let the browser decide the color of the cursor, which uses the current text color, we use the auto value. The current text color will be applied to the cursor. This is shown in the following example.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
      div {
         display: grid;
         gap: 20px;
         width: 60%;
      }
      .inp {
         border: 2px solid black;
         font-size: 16px;
         padding: 5px;
         caret-color: auto;
      }
      .text {
         color: blue;
      }
      .textarea {
         color: red;
      }
    </style></head><body><h2>
      CSS caret-color property
    </h2><div><label>
         caret-color: auto (color of the text will
         be applied to caret)
      &lt;/label&gt;&lt;input type="text" value="Default cursor color."
      class=" inp text" 
      /&gt;&lt;textarea rows="10" 
      class=" inp textarea"&gt;Default caret color.
      &lt;/textarea&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Caret Color Property with Color Values

    To give a color of our choice to the cursor, we can specify the color in different format (color names, hex values, rgb values, hsl values etc.). The specified color will be applied to the cursor. This is shown in the following example.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
      div {
         display: grid;
         gap: 20px;
         width: 60%;
      }
      .inp {
         border: 2px solid black;
         font-size: 20px;
         padding: 5px;
      }
      .text1 {
         caret-color: orange;
      }
      .text2 {
         caret-color: #ff4d94;
      }
      .text3 {
         caret-color: rgb(0, 204, 204);
      }
      .textarea {
         caret-color: hsl(120, 100%, 50%);
      }
    </style></head><body><h2>
      CSS caret-color property
    </h2><div><label>
         caret-color: color values (specified color will
         be applied to caret.)
      &lt;/label&gt;&lt;input type="text" value="Green caret color."
      class=" inp text1" 
      /&gt;&lt;input type="text" value="Pink cursor color."
      class=" inp text2" 
      /&gt;&lt;input type="text" value="Blue cursor color."
      class=" inp text3" 
      /&gt;&lt;textarea rows="10" 
      class=" inp textarea"&gt;green cursor color.
      &lt;/textarea&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Caret Color Property with Transparent Value

    To make the cursor transparent such that it is not visible, we use the transparent value. This is shown in the following example.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
      div {
         display: grid;
         gap: 20px;
         width: 60%;
      }
      .inp {
         border: 2px solid black;
         font-size: 16px;
         padding: 5px;
         caret-color: transparent;
      }
    </style></head><body><h2>
      CSS caret-color property
    </h2><div><label>
         caret-color: transparent (cursor color 
         will not be visible)
      &lt;/label&gt;&lt;input type="text" value="transparent caret."
      class="inp" 
      /&gt;&lt;textarea rows="10" 
      class=" inp"&gt;transparent caret. 
      &lt;/textarea&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Supported Browsers

    PropertyChromeEdgeFirefoxSafariOpera
    caret-color57.079.053.011.144.0
  • box-decoration-break Property

    CSS box-decoration-break property specifies how the background, border, border-image, box-shadow, margin, padding and clip-path of an element should behave when the content is broken across multiple lines or columns. It controls whether these properties should be continuous or fragmented across the line breaks.

    Syntax

    box-decoration-break: slice | clone | initial | inherit;

    Property Values

    ValueDescription
    sliceIt means that the padding, border, and background of the element will be rendered as if the content were not broken, resulting in continuous rendering across line breaks. Default Value
    cloneEach box fragment is rendered individually with its defined border, padding, and margin wrapping it. The border-radius and box-shadow are applied to each fragment separately.
    initialIt sets the property to its default value.
    inheritIt inherits the property from the parent element.

    Examples of CSS Box Decoration Break Property

    The following examples explain the box-decoration-break property with different values.

    Box Decoration Break Property with Slice Value

    To let the box decoration properties be rendered continuously such that they break at the edges of the element fragment, we use the slice value. This is shown in the following example.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
      span {
         -webkit-box-decoration-break: slice;
         box-decoration-break: slice;
      }
      .box {
         background-color: lightblue;
         border: 5px solid green;
         padding: 10px;
         border-radius: 15px;
         line-height: 3;
      }
    </style></head><body><h2>
      CSS box-decoration-break property
    </h2><span class="box">
         CSS
      &lt;br&gt;
         box-decoration-break property 
      &lt;br&gt; 
         with slice
      &lt;br&gt;
         Value. 
      &lt;br&gt;
         See how the 
      &lt;br&gt; 
         properties are applied 
      &lt;br&gt;
         to the elements.
    </span></body></html>

    Box Decoration Break Property with Clone Value

    To let each individual element fragment have individual box decoration properties separately, we use the clone value. The value treats each element broken across multiple lines as individual element and applies the properties to each of them. This is shown in the following example.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
      span {
         -webkit-box-decoration-break: clone;
         box-decoration-break: clone;
      }
      .box {
         background-color: lightblue;
         border: 5px solid green;
         padding: 10px;
         border-radius: 15px;
         line-height: 3;
      }
    </style></head><body><h2>
      CSS box-decoration-break property
    </h2><span class="box">
      CSS
    <br>
      box-decoration-break property 
    <br>
      with clone
    <br>
      Value. 
    <br>
      See how the 
    <br>
      properties are applied 
    <br>
      to the elements.
    </span></body></html>

    Supported Browsers

    PropertyChromeEdgeFirefoxSafariOpera
    box-decoration-break22.079.032.06.111.5
  • box-shadow Property

    CSS box-shadow property adds a shadow effect around an element. One or more shadow effects can be added, separated by commas. The box shadow is described by horizontal and vertical offsets relative to the element, blur, spread radius and color.

    Syntax

    box-shadow: none | h-offset v-offset blur spread color | inset | initial | inherit;

    Property Values

    ValueDescription
    noneThis value does not show any shadow. Default
    h-offsetIt defines the horizontal offset. Positive values place the shadow to the right of box, negative values place the shadow to the left of box. Required.
    v-offsetIt defines the vertical offset. Positive values place the shadow below the box, negative values place the shadow above the box. Required
    blurIt defines the blur radius. Higher values have higher blur. Optional.
    spreadIt defines the spread radius. Positive values increases size of shadow, negative values decreases size of shadow. Optional
    colorIt defines the color of the shadow. Different formats of color can be used. Default is color of text. Optional
    insetIt changes the outer shadow to inner shadow.
    initialIt sets the property to its default value.
    inheritIt inherits the property from the parent element.

    Examples of CSS Box Shadow Property

    The following examples explain the box-shadow property with different values.

    Box Shadow Property with Box Shadow

    To set a shadow to a box, we require to specify atleast two values, one for the horizontal offset and the other for the vertical offset. Depending on the signs of the values, the position of the shadow changes accordingly. This is shown in the following example.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        .container {
            display: grid;
            justify-content: center;
            align-items: center;
            gap: 30px;
        }
        .boxes {
            padding: 50px;
            text-align: center;
            font-weight: bold;
        }
        .first {
            background-color: lightcoral;
            box-shadow: 10px 10px;
        }
        .second {
            background-color: lightblue;
            box-shadow: 10px -10px;
        }
        .third {
            background-color: lightgreen;
            box-shadow: -10px 10px;
        }
        .fourth {
            background-color: lightgrey;
            box-shadow: -10px -10px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;
        CSS box-shadow property
    &lt;/h2&gt;&lt;p&gt;
        Positive horizontal offset places the shadow
        to the right of box and negative horizotal offset
        places the shadow to the left of box. 
    &lt;/p&gt;&lt;p&gt;
        Positive vertical offset places the 
        shadow below the box and negative values places
        it above the box.
    &lt;/p&gt;&lt;div class="container"&gt;&lt;p class="first boxes"&gt;
            box-shadow: 10px 10px
        &lt;/p&gt;&lt;p class="second boxes"&gt;
            box-shadow: 10px -10px
        &lt;/p&gt;&lt;p class="third boxes"&gt;
            box-shadow: -10px 10px
        &lt;/p&gt;&lt;p class="fourth boxes"&gt;
            box-shadow: -10px -10px
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Box Shadow Property with Blur

    To set a blur to the shadow of a box, we require to specify three values. The first two values are the horizontal and vertical offsets while the third value is for the blur, higher the third value greter will be the blur. This is shown in the following example.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        .container {
            display: grid;
            justify-content: center;
            align-items: center;
            gap: 30px;
        }
        .boxes {
            padding: 50px;
            text-align: center;
            font-weight: bold;
        }
        .first {
            background-color: lightcoral;
            box-shadow: 10px 10px 10px;
        }
        .second {
            background-color: lightcoral;
            box-shadow: 10px 10px 20px;
        }
        .third {
            background-color: lightcoral;
            box-shadow: 10px 10px 40px;
        }    
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;
        CSS box-shadow property
    &lt;/h2&gt;&lt;p&gt;
        The third value decides the blur, 
        greater the value more is the blur.
    &lt;/p&gt;&lt;div class="container"&gt;&lt;p class="first boxes"&gt;
            box-shadow: 10px 10px 10px
        &lt;/p&gt;&lt;p class="second boxes"&gt;
            box-shadow: 10px -10px 20px
        &lt;/p&gt;&lt;p class="third boxes"&gt;
            box-shadow: -10px 10px 40px
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Box Shadow Property with Spread Value

    To set the size of the shadow of a box, we require to specify four values. The first two values are the horizontal and vertical offsets while the third value is for the blur, the fourth value decides the size of the shadow, positive values result in larger shadows while negative values result in smaller shadows. This is shown in the following example.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        .container {
            display: grid;
            justify-content: center;
            align-items: center;
            gap: 30px;
        }
        .boxes {
            padding: 50px;
            text-align: center;
            font-weight: bold;
        }
        .first {
            background-color: lightblue;
            box-shadow: 10px 10px 10px 5px;
        }
        .second {
            background-color: lightblue;
            box-shadow: 10px 10px 20px 15px;
        }
        .third {
            background-color: lightblue;
            box-shadow: 10px 10px 40px -5px;
        }    
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;
        CSS box-shadow property
    &lt;/h2&gt;&lt;p&gt;
        The fourth value decides the size of the shadow, 
        positive value results in larger shadow while negative
        value results in smaller shadow.
     &lt;/p&gt;&lt;div class="container"&gt;&lt;p class="first boxes"&gt;
            box-shadow: 10px 10px 10px 5px
        &lt;/p&gt;&lt;p class="second boxes"&gt;
            box-shadow: 10px -10px 20px 14px
        &lt;/p&gt;&lt;p class="third boxes"&gt;
            box-shadow: -10px 10px 40px -5px
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Box Shadow Property with Color Value

    To set a color to the shadow of a box, we require to specify atleast three values. The first two values are the horizontal and vertical offsets while the third value is for the color, the color can be specified along with blur and spread as well. The color can be specified in different format (eg. color names, hexadecimal values, rgb values etc.). This is shown in the following example.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        .container {
            display: grid;
            justify-content: center;
            align-items: center;
            gap: 30px;
        }
        .boxes {
            padding: 50px;
            text-align: center;
            font-weight: bold;
        }
        .first {
            background-color: lightcoral;
            box-shadow: 10px -10px grey;
        }
        .second {
            background-color: lightcoral;
            box-shadow: 10px 10px 20px rgb(51, 204, 0);
        }
        .third {
            background-color: lightcoral;
            box-shadow: 10px 10px 40px -5px hsl(225, 100%, 50%);
        }    
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;
        CSS box-shadow property
    &lt;/h2&gt;&lt;p&gt;
        The color can be specified as third parameter,
        fourth parameter of even fifth parameter. 
        The specified color will be applied to the shadow.
     &lt;/p&gt;&lt;div class="container"&gt;&lt;p class="first boxes"&gt;
            box-shadow: 10px -10px grey
        &lt;/p&gt;&lt;p class="second boxes"&gt;
            box-shadow: 10px 10px 20px rgb(51, 204, 0)
        &lt;/p&gt;&lt;p class="third boxes"&gt;
            box-shadow: 10px 10px 40px -5px hsl(225, 100%, 50%)
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Box Shadow Property with Inset Value

    To let the box shadow appear inside the element and not outside the element, we use the inset value. This is shown in the following example

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        .container {
            display: grid;
            justify-content: center;
            align-items: center;
            gap: 30px;
        }
        .boxes {
            padding: 50px;
            text-align: center;
            font-weight: bold;
        }
        .first {
            background-color: lightgreen;
            box-shadow: 10px -10px red inset;
        }
        .second {
            background-color: lightgreen;
            box-shadow: 10px 10px 20px rgb(51, 204, 0) inset;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;
    CSS box-shadow property
    &lt;/h2&gt;&lt;p&gt;
        The inset value places the
        shadow within the elment.
    &lt;/p&gt;&lt;div class="container"&gt;&lt;p class="first boxes"&gt;
            box-shadow: 10px -10px red inset
        &lt;/p&gt;&lt;p class="second boxes"&gt;
            box-shadow: 10px 10px 20px rgb(51, 204, 0) inset
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Box Shadow Property with Multiple Shadows

    To have multiple shadows for a box, each style must be comma separated. The shadows will appear in the order specified in box-shadow property. This is shown in the following example.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        .container {
            display: grid;
            justify-content: center;
            align-items: center;
            gap: 30px;
        }
        .boxes {
            padding: 50px;
            text-align: center;
            font-weight: bold;
        }
        .first {
            background-color: lightcoral;
            box-shadow: 10px -10px grey, 
            15px -15px black, 
            20px -20px brown;
        }
        .second {
            background-color: lightgreen;
            box-shadow: 5px 5px red, 
            10px 10px blue, 
            15px 15px green;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;
    CSS box-shadow property
    &lt;/h2&gt;&lt;p&gt;
        Number of shadows can be altered by 
        specifying the different styles and
        separating them by commas. 
    &lt;/p&gt;&lt;div class="container"&gt;&lt;p class="first boxes"&gt;
            box-shadow: multiple shadows
        &lt;/p&gt;&lt;p class="second boxes"&gt;
            box-shadow: multiple shadows
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Supported Browsers

    PropertyChromeEdgeFirefoxSafariOpera
    box-shadow10.09.04.05.110.5
  • Gradients

    CSS gradients allows to design custom colors for HTML elements by creating a smooth transition between two or more colors.

    What is CSS Gradient?

    • In CSS, gradient is a special type of user defined images that can be used for background or borders of element.
    • We can set a gradient to background property of any HTML elements using function gradient(type, color1, color2, color3);
    • Zooming a image gradient does not loose it’s quality as this are defined by browsers according to developers code.

    Table of Contents

    • Types of CSS Gradients
    • Linear Gradients
    • Radial Gradients
    • Conic Gradients
    • Gradients for Borders
    • Positioning Color Stops
    • Creating Hard Lines
    • Color Bands Using Gradients
    • Stacked Gradients
    • Related Functions

    Types of CSS Gradients

    CSS defines three types of gradients

    • Linear Gradient: Goes from left to right, up to down or diagonally.
    • Radial Gradient: Start from center to edges.
    • Conic Gradient: Revolve around a center point.

    Linear GradientRadial GradientConic Gradient

    Choose a gradient for background

    Linear Gradients

    The linear gradient creates a color band that flows in a single direction, i.e. from left-to-right, top-to-bottom, or at any angle.

    Syntax

    linear-gradient(direction, color1, color2, ...);/* Gradient from bottom right to top left */linear-gradient(to top left, color1, color2, ...);/* Gradient at an angle 45 degree */linear-gradient(45deg, red, yellow);

    The direction parameter specifies the angle or direction ( [to left | to right] || [to top | to bottom]) of the gradient.

    Example

    In order to create a basic linear gradient, you just need two colors, which are known as color stops. You must have minimum two, but can have more than two as well.

    Following example demonstrates this:

    Open Compiler

    <html><head><style>
    
      div {
         height: 70px;
         width: 100%;
      }
      .topBottom {
         background: linear-gradient(green, yellow);
      }
      .RightLeft{
         background: linear-gradient(to right, green, yellow);
      }
    </style></head><body><h1>Linear gradient</h1><h3>Top to Bottom ( Default )</h3><div class="topBottom"></div><h3>Right to left</h3><div class="RightLeft"></div></body></html>

    Radial Gradients

    radial gradient is a type of gradient that consists of colors radiating outward from a central point.

    In a radial gradient, the colors smoothly transition from one color at the center to another color at the outer edges in a circular or elliptical pattern.

    Syntax

    radial-gradient(shape size position, color1, color2..);
    • The shape parameter defines the shape of the gradient (circle or ellipse).
    • The size parameter specifies the size of the shape.
    • The position parameter sets the center of the gradient

    Example

    In order to create a basic radial gradient, you just need two colors. The center of the gradient is at 50% 50% mark, by default; where the gradient is elliptical matching with the aspect ratio of its box.

    Let us see an example:

    Open Compiler

    <html><head><style>
    
      div {
         height: 100px;
         width: 100%;
      }
      .gradient {
         background: radial-gradient(green, yellow);
      } 
      .center-gradient {
         background:
            radial-gradient(
               at 0% 50%,
               green 30px,
               yellow 60%,
               magenta 20%
            );
      }
    </style></head><body><h1>Radial gradient</h1><h3>Simple Radial Gradient</h3><div class="gradient"></div><h3>Center Positioned Radial Gradient</h3><div class="center-gradient"></div></body></html>

    Conic Gradients

    conic gradient, also known as a conical gradient or angular gradient, is a type of gradient in which colors are arranged in a circular or conical pattern, radiating out from a central point in a 360-degree arc.

    Syntax

    conic-gradient(from 'angle' at 'position','color-list')
    • position (optional): Specifies the position of the starting point of the gradient. It can be a percentage or a keyword like center.
    • angle (optional): Specifies the starting angle of the gradient in degrees.
    • color-list : Defines the colors and their positions in the gradient.

    Example

    In this example we will create a conic gradient pie chart with four different colors, then align gradient at different locations of diagram.

    Open Compiler

    <!DOCTYPE html><html lang="en"><head><style>
    
      div {
         height: 80px;
         width: 110px;
         border-radius: 50%; 
      }
      .gradient1{
         background: conic-gradient(
                        from 45deg at 50% 50%, 
                        red, yellow, green, 
                        blue, red);
      }
      .gradient2{
         background: conic-gradient(
                        from 45deg at 20% 40%, 
                        red, yellow, green, 
                        blue, red);
      }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Conic Gradient Example&lt;/h1&gt;&lt;h3&gt;Align at center&lt;/h3&gt;&lt;div class="gradient1"&gt;&lt;/div&gt;&lt;h3&gt;Align at 20-40&lt;/h3&gt;&lt;div class="gradient2"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Gradients for Borders

    The CSS gradients can be used to create fancy borders as well. You can use the gradients in wide variety to create effects in the border patterns.

    Syntax

    border-image:linear-gradient('color-list')

    You can also use radial and conical gradients for borders.

    Example

    Here is an example of use of gradients in creation of borders:

    Open Compiler

    <!DOCTYPE html><html lang="en"><head><style>
    
         .gradient-border {
            height: 200px;
            width: 200px;
            border: 10px solid;
            border-image: linear-gradient(
                              to right, 
                              red, yellow, 
                              green, blue) 1;
         }
      &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Gradient Border &lt;/h2&gt;&lt;div class="gradient-border"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Positioning Color Stops

    Positioning color stops for gradient allows to control the point at which transition occur for a gradient.

    Syntax

    linear-gradient(to right, red 10%, pink 30%, blue 60%)
    • to right: Specifies the direction of gradient.
    • red 10%: Sets the red color to stop at 10% of the gradient
    • pink 30%: Sets the pink color to stop at 30% of the gradient.
    • blue 60%: Sets the blue color to stop at 60% of the gradient.

    Example

    Open Compiler

    <html><head><style>
    
      div {
         height: 100px;
         width: 100%;
      }
      .linear-position {
         background: linear-gradient(to right, 
                        blue 15px, magenta 33%, 
                        red 66%, yellow 60%, 
                        orange 100%);
      }
    </style></head><body><div class="linear-position"></div></body></html>

    Creating Hard Lines

    A hard line can be created in between two colors, such that no smooth transition can be seen. This effect can be achieved by carefully positioning color stops in CSS gradients. Check out following example

    Example

    In this example we will create hard line using gradient function.

    Open Compiler

    <html><head><style>
    
      div {
         height: 100px;
         width: 100px;
         display: inline-block;
         text-align: center;
         margin: 5px;
      }
      .linear-hard-line {
         background: linear-gradient(to top right, 
                           green 50%, orange 50%);
      }
    </style></head><body><div class="linear-hard-line"></div></body></html>

    Color Bands Using Gradients

    In order to create a striped effect, the second color stop for each color is set at the same location as the first color stop for the adjacent color.

    Syntax

    linear-gradient(to right, red 10%, 
    
               pink 10% 30%, 
               blue 60% 80%,
               yellow 80%);</pre>

    Example

    In this example will create a multi colored color band.

    Open Compiler

    <html><head><style>
    
      div {
         height: 100px;
         width: 100%;
      }
      .linear-gradient-stripes {
         background: linear-gradient(
                     to right,
                     green 20%,
                     lightgreen 20% 40%, 
                     orange 40% 60%,
                     yellow 60% 80%,
                     red 80%);
      }
    </style></head><body><div class="linear-gradient-stripes"></div></body></html>

    Stacked Gradients

    One gradient can be stacked over other gradients. Just make sure the gradient at the top should not be completely opaque, so that the gradients below it can be seen.

    Example

    Lets see an example of stacked gradients.

    Open Compiler

    <html><head><style>
    
      div {
         height: 200px;
         width: 100%;
      }
      .stacked-linear {
         background: 
            linear-gradient(90deg, green, yellow),
            linear-gradient(220deg, white 70.71%, black 38%),
            linear-gradient(217deg, orange, grey 70.71%);
      }
    </style></head><body><div class="stacked-linear"></div></body></html>

  • Colors

    CSS uses color values to specify a color. Typically, these are used to set a color either for the foreground of an element (i.e. its text) or else for the background of the element. They can also be used to affect the color of borders and other decorative effects.

    You can specify your color values in various formats. Following table lists all the possible formats −

    FormatSyntaxDescriptionExample
    Keyword<property>: <colorname>CSS has a set of predefined color names that you can use directly.red, blue, green, yellow, black, white, etc.
    Hexadecimal Code#RRGGBBStarts with a hash (#) followed by six hexadecimal digits.#FF0000 – red
    Short Hexadecimal Code#RGBShorter version of hexadecimal format where each of the RGB components is represented by a single digit, and the value is duplicated.#F00 – red
    RGBrgb(red,green,blue)Colors can be defined using the rgb() function, which takes three parameters representing the red, green, and blue values.rgb(0, 0, 255) – blue
    RGBArgba()Similar to RGB, with an additional parameter for the alpha (transparency) value. 0 (fully transparent) and 1 (fully opaque)rgba(0,0,255,0.5) – translucent blue
    HSLhsl()Colors can be defined using the rgb() function which stands for Hue (0 to 360 degree), Saturation (%), and Lightness (%).hsl(120, 100%, 50%) – pure green
    HSLAhsla()Similar to HSL, with an additional parameter for the alpha (transparency) value.hsl(120, 100%, 50%, 0.5) – translucent green
    currentcolor KeywordcurrentcolorIt refers to the value of the color property of the element.color: red; /* Red text color */ border: 10px solid currentcolor; /* Red border color */
    System coloras per OS or browserCSS allows usage of system colors defined by the user’s OS or browser.ButtonText, Window, WindowText

    These formats are explained in more detail in the following sections −

    CSS Colors – Keyword

    CSS supports the color names to be directly passed to the property background-color and color. 140 standard color names are supported by CSS.

    Few of the examples are listed in the table below:

    ColorColor Name
     Black
     Red
     Blue
     Green
     Aquamarine

    Here is an example:

    Open Compiler

    <html><head><style>
       #colorkeyword{
    
      background-color: aqua;
      padding: 10px;
    } </style></head><body><h3>Color Keyword - example</h3><p>As the keyword passed is aqua, the background will appear as aqua colored..</p><div id="colorkeyword">
      This div element has a colored background based on the color keyword passed, i.e aqua.
    </div></body></html>

    CSS Colors – Hexadecimal Codes

    A hexadecimal is a 6 digit representation of a color. The first two digits(RR) represent a red value, the next two are a green value(GG), and the last are the blue value(BB).

    A hexadecimal value can be taken from any graphics software like Adobe Photoshop, Jasc Paintshop Pro, or even using Advanced Paint Brush.

    Each hexadecimal code will be preceded by a pound or hash sign ‘#’. Following are the examples of hexadecimal notation.

    Note: To specify the hexadecimal codes, you can use upper case or lower case letters.

    ColorColor Hexadecimal Code
     #000000
     #FF0000
     #00FF00
     #0000FF
     #FFFF00
     #00FFFF
     #FF00FF
     #C0C0C0
     #FFFFFF

    Here is an example:

    Open Compiler

    <html><head><style>
       #hexcode {
    
      background-color: #00ff00;
      padding: 10px;
    } </style></head><body><h3>Hexadecimal code - example</h3><p>As the hexadecimal code is #00ff00 the background will appear green.</p><div id="hexcode">
         This div element has a green background.
      &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Colors - Short Hexadecimal Codes

    This is a shorter form of the six-digit notation. In this format, each digit is replicated to arrive at an equivalent six-digit value. For example: #6A7 becomes #66AA77.

    A hexadecimal value can be taken from any graphics software like Adobe Photoshop, Jasc Paintshop Pro, or even using Advanced Paint Brush.

    Each short hexadecimal code will be preceded by a pound or hash sign '#'. Following are the examples of short hexadecimal notation.

    Note: To specify the hexadecimal codes, you can use upper case or lower case letters.

    ColorShort Hexadecimal Code
     #000
     #F00
     #0F0
     #0FF
     #FF0
     #0FF
     #F0F
     #FFF

    Here is an example:

    Open Compiler

    <html><head><style>
       #shorthex {
    
      background-color: #00f;
      padding: 10px;
    } </style></head><body><h3>Short Hexadecimal code - example</h3><p>As the short hexadecimal code is #00f the background will appear blue.</p><div id="shorthex">
         This div element has a blue background.
      &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Colors - RGB Values

    • This color value is specified using the rgb( ) property.
    • It takes three values, one each for red, green, and blue.
    • The value can be an integer between 0 and 255 or a percentage.

    NOTE: All the browsers does not support rgb() property of color so it is recommended not to use it.

    Following is the example to show few colors using RGB values.

    ColorColor RGB
     rgb(0,0,0)
     rgb(255,0,0)
     rgb(0,255,0)
     rgb(0,0,255)
     rgb(255,255,0)
     rgb(0,255,255)
     rgb(255,0,255)
     rgb(192,192,192)
     rgb(255,255,255)

    Here is an example:

    Open Compiler

    <html><head><style>
       #rgbvalue {
    
      background-color: rgb(255,0,255);
      padding: 10px;
    } </style></head><body><h3>RGB - example</h3><p>As the rgb(255,0,255) is set the background will appear accordingly.</p><div id="rgbvalue">
      This div element has a colored background based on the rgb values.
    </div></body></html>

    CSS Colors - RGBA Values

    • This color value is specified using the rgba( ) property.
    • It takes four values, one each for red, green, and blue and the last value as the alpha (transparency) value.
    • The alpha value can be any value between 0 and 1.

    NOTE: All the browsers do not support rgba() property of color so it is not recommended.

    Following is the example to show few colors using RGBA values.

    ColorColor RGBA
     rgba(0,0,0,0)
     rgba(255,0,0,0.2)
     rgba(0,255,0,0.3)
     rgba(0,0,255,0.5)
     rgba(255,255,0,0.7)
     rgba(0,255,255,0.1)
     rgba(255,0,255,1)
     rgba(192,192,192,0.4)
     rgba(255,255,255,1)

    Here is an example:

    Open Compiler

    <html><head><style>
       #rgbavalue {
    
      background-color: rgba(255,0,255,0.2);
      padding: 10px;
    } </style></head><body><h3>RGBA - example</h3><p>As the rgba(255,0,255,0.2) is set the background will appear with transparency value of 0.2.</p><div id="rgbavalue">
      This div element has a colored background based on the rgba values.
    </div></body></html>

    CSS Colors - HSL Values

    • This color value is specified using the hsl() function.
    • HSL stands for hue, saturation and lightness.
    • Hue is represented in degrees (0-360), saturation and lightness are represented as percentages (0% - 100%).

    Following is the example to show few colors using HSL property.

    ColorColor HSL
     hsl(0,0%,50%)
     hsl(255,80%,70%)
     hsl(290,100%,60%)
     hsl(360,70%,20%)
     hsl(89,80%,67%)

    Here is an example:

    Open Compiler

    <html><head><style>
       #hslvalue {
    
      background-color: hsl(355,70%,50%);
      padding: 10px;
    } </style></head><body><h3>HSL - example</h3><p>As the hsl(355,70%,50%) is set the background will appear based on the hsl values passed.</p><div id="hslvalue">
      This div element has a colored background based on the hsl values hsl(355,70%,50%).
    </div></body></html>

    CSS Colors - HSLA Values

    • This color value is specified using the hsl() function.
    • HSLA stands for hue, saturation, lightness and alpha.
    • It takes four values, first for hue, second for saturation, third for lightness and fourth is the alpha (transparency) value.
    • Hue is represented in degrees (0-360), saturation and lightness are represented as percentages (0% - 100%), and alpha value can be in between 0 and 1.

    Following is the example to show few colors using HSLA property.

    ColorColor HSLA
     hsla(0,0%,50%,0.5)
     hsla(255,80%,70%,1)
     hsla(290,100%,60%,0.2)
     hsla(360,70%,20%,0.4)
     hsla(89,80%,67%,0.9)

    Here is an example:

    Open Compiler

    <html><head><style>
       #hslavalue {
    
      background-color: hsla(355,70%,50%,0.4);
      padding: 10px;
    } </style></head><body><h3>HSLA - example</h3><p>As the hsla(355,70%,50%,0.4) is set the background will appear based on the hsla values passed, with high transparency.</p><div id="hslavalue">
      This div element has a colored background based on the hsl values hsla(355,70%,50%,0.4).
    </div></body></html>

    CSS Colors - currentcolor keyword

    The currentcolor keyword signifies the value of the color property of an element. It can be passed to any other styling property using the keyword currentcolor.

    Here is an example:

    Open Compiler

    <html><head><style>
       #currcolor {
    
      color: red;
      border: 5px solid currentcolor;
    } </style></head><body><h2>The currentcolor Keyword</h2><p>As the currentcolor keyword is used for border after color property is set as red, the border will also appear red.</p><div id="currcolor">
      This div element has a red text color and a red border.
    </div></body></html>

    CSS Colors - Building Color Codes

    You can build millions of color codes using our Color Code Builder. Check the HTML Color Code Builder.

    To use this tool, you would need a Java Enabled Browser.

    CSS Colors - Browser Safe Colors

    Here is the list of 216 colors which are supposed to be most safe and computer independent colors. These colors vary from hexa code 000000 to FFFFFF. These colors are safe to use because they ensure that all computers would display the colors correctly when running a 256 color palette −

    0000000000330000660000990000CC0000FF
    0033000033330033660033990033CC0033FF
    0066000066330066660066990066CC0066FF
    0099000099330099660099990099CC0099FF
    00CC0000CC3300CC6600CC9900CCCC00CCFF
    00FF0000FF3300FF6600FF9900FFCC00FFFF
    3300003300333300663300993300CC3300FF
    3333003333333333663333993333CC3333FF
    3366003366333366663366993366CC3366FF
    3399003399333399663399993399CC3399FF
    33CC0033CC3333CC6633CC9933CCCC33CCFF
    33FF0033FF3333FF6633FF9933FFCC33FFFF
    6600006600336600666600996600CC6600FF
    6633006633336633666633996633CC6633FF
    6666006666336666666666996666CC6666FF
    6699006699336699666699996699CC6699FF
    66CC0066CC3366CC6666CC9966CCCC66CCFF
    66FF0066FF3366FF6666FF9966FFCC66FFFF
    9900009900339900669900999900CC9900FF
    9933009933339933669933999933CC9933FF
    9966009966339966669966999966CC9966FF
    9999009999339999669999999999CC9999FF
    99CC0099CC3399CC6699CC9999CCCC99CCFF
    99FF0099FF3399FF6699FF9999FFCC99FFFF
    CC0000CC0033CC0066CC0099CC00CCCC00FF
    CC3300CC3333CC3366CC3399CC33CCCC33FF
    CC6600CC6633CC6666CC6699CC66CCCC66FF
    CC9900CC9933CC9966CC9999CC99CCCC99FF
    CCCC00CCCC33CCCC66CCCC99CCCCCCCCCCFF
    CCFF00CCFF33CCFF66CCFF99CCFFCCCCFFFF
    FF0000FF0033FF0066FF0099FF00CCFF00FF
    FF3300FF3333FF3366FF3399FF33CCFF33FF
    FF6600FF6633FF6666FF6699FF66CCFF66FF
    FF9900FF9933FF9966FF9999FF99CCFF99FF
    FFCC00FFCC33FFCC66FFCC99FFCCCCFFCCFF
    FFFF00FFFF33FFFF66FFFF99FFFFCCFFFFFF

    CSS Colors - Related Properties

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

    PropertyDescription
    opacitySets the transparency level of an element.
    hueRepresents the hue angle of an element.
    colorSets the foreground of an element's text and text decoration.
    background-colorSets the color of the background.
    border-colorSets the color of the border of an element.
    box-shadowAdds a shadow effect around an element.
    outline-colorSets the color of the outline around an element.
    text-shadowAdds shadow to the text of an element.
  • Multiple Backgrounds

    In CSS, you can use multiple background images for an element. First background should be layered on top, and the last background should be layered behind. Only the last background can have a background color.

    Syntax

    .multibackgrounds {
       background:
    
      background1,
      background2,
      /* , */ backgroundN;
    }

    You can use shorthand and individual background properties, excluding background-color.

    The following background properties can be provided as a list, one for each background: backgroundbackground-attachmentbackground-clipbackground-imagebackground-originbackground-positionbackground-repeatbackground-size.

    CSS Multiple Backgrounds – Using background-image property

    The following example demonstrates adding two background images using background-image property, where the first image is stacked on top and the second is behind it −

    Open Compiler

    <html><head><style>
       .multibackgrounds {
    
      background-image: url(images/logo.png), url(images/see.jpg);
      background-position: left top, right top;
      background-repeat: no-repeat, repeat;
      padding: 70px;
    } </style></head><body><div class="multibackgrounds"><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p></div></body></html>

    CSS Multiple Backgrounds – Using background-size Property

    The following example demonstrates the use of multiple background images of different sizes using background-size property. The first image’s size is 150px, and the second image’s size is 300px −

    Open Compiler

    <html><head><style>
       .multibackgrounds{
    
      background-image: url(images/logo.png), url(images/see.jpg);
      background-position: left top, right top;
      background-repeat: no-repeat, repeat;
      padding: 70px;
    } .multibackgrounds-size {
      background-image: url(images/logo.png), url(images/see.jpg);
      background-position: left top, right top;
      background-repeat: no-repeat, repeat;
      background-size: 150px, 300px;
      padding: 70px;
    } </style></head><body><h3>Without Sizing</h3><div class="multibackgrounds"><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p></div><br><h3>With Sizing</h3><div class="multibackgrounds-size"><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p></div></body></html>

    CSS Multiple Backgrounds – Using background Property

    The following example demonstrates addition of three background images using the shorthand property background −

    Open Compiler

    <html><head><style>
       .multibackgrounds-size {
    
      background: url(images/logo.png),  url(images/pink-flower.jpg), url(images/see.jpg);
      background-position: left top, center, right top;
      background-repeat: no-repeat, no-repeat, no-repeat;
      background-size: 150px, 100px, 550px;
      padding: 70px;
      color: yellow;
    } </style></head><body><div class="multibackgrounds-size"><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p></div></body></html>

    CSS Multiple Backgrounds – Full Size Image

    The following example demonstrates full sized background image, set using background-size: cover property −

    Open Compiler

    <html><head><style> 
       html { 
    
      background: url(images/red-flower.jpg) no-repeat center fixed; 
      background-size: cover;
      color: yellow; 
    } </style></head><body><h1>Red Flower Image</h1><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p></body></html>

    CSS Multiple Backgrounds – Hero Image

    The following example demonstrates the setting of a hero image, refers to a large image with text using different background properties on <div> −

    Open Compiler

    <html><head><style>
       .background-img {
    
      background: url(images/see.jpg) no-repeat center; 
      background-size: cover;
      height: 300px;
      position: relative;
    } .background-text {
      text-align: center;
      position: absolute;
      top: 40%;
      left: 50%;
      transform: translate(-50%, -50%);
      color: red;
    } button {
         background-color: yellow;
         padding: 10px;
    } </style></head><body><div class="background-img"><div class="background-text"><h1>See Image</h1><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p><button>Click Me</button></div></div></body></html>

    CSS Multiple Backgrounds – Using background-origin Property

    The following example demonstrates how the background image is positioned within a box using background-origin property −

    Open Compiler

    <html><head><style>
       div {
    
      width: 200px;
      height: 150px;
      border: 7px solid blue;
      padding: 30px;
      background: url(images/pink-flower.jpg);
      background-repeat: no-repeat;
      margin: 10px;
    } P {
      color: yellow;
    } h3 {
      color: red;
    } .box1 {
      background-origin: padding-box;
    } .box2 {
      background-origin: border-box;
    } .box3 {
      background-origin: content-box;
    } </style></head><body><div class="box1"><h3>background-origin: padding-box</h3><p>Background image is positioned relative to the padding box.</p></div><div class="box2"><h3>background-origin: border-box</h3><p>Background image is positioned relative to the border box.</p></div><div class="box3"><h3>background-origin: content-box</h3><p>Background image is positioned relative to the content box.</p></div></body></html>

    CSS Multiple Backgrounds – Using background-clip Property

    The following example demonstrates how the background image should be displayed within box using background-clip property −

    Open Compiler

    <html><head><style>  
       p {
    
      width: 200px;
      height: 150px;
      border: 8px solid blue;
      margin: 10px;
      padding: 30px;
      color: yellow;
      background: url(images/pink-flower.jpg);
    } .box1 {
      background-clip: border-box;
    } .box2 {
      background-clip: padding-box;
    } .box3 {
      background-clip: content-box;
    } </style></head><body><p class="box1">Background image is applied to the entire element.</p><p class="box2">Background image is applied to the padding area.</p><p class="box3">Background image is applied only to the content area.</p></body></html>

    CSS Multiple Backgrounds – Related Properties

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

    PropertiesDescription
    backgroundShorthand for background related properties.
    background-attachmentSpecifies the position of the background relative to the viewport, either fixed or scrollable.
    background-clipControls how far a background image extends beyond the element’s padding or content box.
    background-imageSets one or more background image(s) on an element.
    background-originSets the origin of the background.
    background-positionSets the initial position of each image in a background.
    background-repeatControls the repetition of an image in the background.
    background-sizeControls the size of the background image.
  • Border Images

    CSS border-images properties are used to create custom borders by setting image as border around any element.

    The border-image property takes the image and slices it into nine sections(3×3). It then places the corners at the corner of the border, and the edges are repeated or stretched as you specify. Middle part of image will be ignored.

    Border Image

    Table of Contents

    • Example of Image as Border
    • CSS Border Image Source
    • CSS Border Image Slice
    • CSS Border Image Width
    • CSS Border Image Outset
    • CSS Border Image Repeat
    • Border Image Shorthand
    • CSS Gradient as Border Images
    • Border Image All Properties

    Example of Image as Border

    The following code shows a basic example of how to set image as border.

    Example

    Open Compiler

    <!DOCTYPE html><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 Image Source

    The CSS border-image-source property specifies the source (url) of an image to be passed as a border to an element.

    Example

    Open Compiler

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

    CSS Border Image Slice

    The border-image-slice property defines how the image is sliced into regions, which are then used to draw the borders.

    The following diagram demonstrates how image is sliced to make border. The image is divided into 9 sections: four corners, four edges, and the center.

    border-image-slice structure

    The value in the 'border-image-slice' property specifies how far inward from the edges of the image the slicing should occur. It essentially defines the size of the areas that will be used to create the border.

    The offset for border-image-slice can be provided in terms of percentage or length units but percentages are highly recommended.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        div{
            background-color: #f0f0f0;
            border: 20px solid transparent;
            border-image-source: url(/css/images/scenery2.jpg);
            border-image-slice: 25%;
            padding: 15px;
            width: 50%
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;&lt;p&gt;
            See how border is set for this div...
        &lt;/p&gt;&lt;/div&gt;&lt;p&gt; Here is full image for your reference: &lt;/p&gt;&lt;img src="/css/images/scenery2.jpg" height="160px"&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Border Image Width

    The border-image-width property is used to specify the width of the image to be set as a border.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        div{
            background-color: #f0f0f0;
            border: 20px solid transparent;
            border-image-source: url(/css/images/border.png);
            border-image-width: 5px;
            border-image-slice: 25%;
            padding: 5px;
            margin: 20px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;
        border-image-width: 5px;
    &lt;/div&gt;&lt;div style="border-image-width: 10px;"&gt;
        border-image-width: 10px;
    &lt;/div&gt;&lt;div style="border-image-width: 15px;"&gt;
        border-image-width: 15px;
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Border Image Outset

    The border-image-outset property is used to specify gap between element and border-image. This property pushes the border image outside, beyond the border box.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        div{
            background-color: grey;
            border: 20px solid transparent;
            border-image-source: url(/css/images/border.png);
            border-image-width: 10px;
            border-image-slice: 25%;
            border-image-outset: 0px;
            padding: 5px;
            width: 80%;
            margin: 10px 15px 60px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;
        border-image-outset: 0px;
    &lt;/div&gt;&lt;div style="border-image-outset: 20px;"&gt;
        border-image-outset: 20px;
    &lt;/div&gt;&lt;div style="border-image-outset: 25px;"&gt;
        border-image-outset: 25px;   
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Border Image Repeat

    The border-image-repeat property in used to repeating and stretching nature of image around border. By default the border image gets stretched along the sides.

    The value repeat for this property, repeats the image specified along the sides of the border until the whole length and width got filled.

    It can also take the value as round, apart from stretch and repeat.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        div{
            background-color: #f0f0f0;
            border: 20px solid transparent;
            border-image-source: url(/css/images/border.png);
            border-image-slice: 25%;
            border-image-repeat: repeat;
            padding: 20px;
            width: 80%;
            margin: 10px 15px 60px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;
        Border Image Repeat
    &lt;/div&gt;&lt;div style="border-image-repeat: stretch;"&gt;
        Border Image Stretch
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Border Image Shorthand Property

    The border-image shorthand property allows you to set all the properties related to border images in one declaration.

    border-image: image-source | image-slice | image-repeat;

    Following example shows how to use this property.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        div{
            background-color: #f0f0f0;
            border: 20px solid transparent;
            border-image: url('/css/images/border.png') 30 round;
            padding: 20px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;&lt;p&gt;
            This is an example of border shorthand property....
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Gradient as Border Images

    CSS gradients can also be used to set the border of an element. There are three types of gradients supported: linear, radial and conic.

    Following example shows how to use this property.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><style>
    
        div{
            background-color: #f0f0f0;
            border: 20px solid transparent;
            border-image: linear-gradient(45deg, green, yellow) 1;
            padding: 20px;
            margin: 20px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;
        Border image linear gradient.
    &lt;/div&gt;&lt;div style="border-image: radial-gradient(green, yellow) 1;"&gt;
        Border image radial gradient.
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Border Images All Properties

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

    PropertyDescriptionExample
    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-repeatDetermines 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-sliceShows 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