CSS CSS Tutorial CSS Advanced CSS Responsive Web Design(RWD) CSS Grid CSS Properties Sass Tutorial Sass Functions



border-top

The border-top property is a CSS property that is used to set the style, width, and color of the top border of an element. It is one of the many border properties available in CSS that allows developers to customize the appearance of an element's border.

The border-top property can be used on any HTML element that has a border, including divs, paragraphs, headings, and tables. It is a shorthand property that allows developers to set the style, width, and color of the top border in a single line of code.

Syntax

The syntax for the border-top property is as follows:


border-top: border-width border-style border-color;

The border-width property sets the width of the top border. It can be set to a specific value in pixels, ems, or other units, or it can be set to one of the following values:

  • thin
  • medium
  • thick

The border-style property sets the style of the top border. It can be set to one of the following values:

  • none
  • solid
  • dotted
  • dashed
  • double
  • groove
  • ridge
  • inset
  • outset

The border-color property sets the color of the top border. It can be set to a specific color using a color name, hex code, or RGB value.

Examples

Here are some examples of how the border-top property can be used:


/* Set the top border to a solid red line with a width of 2 pixels */
border-top: 2px solid red;

/* Set the top border to a dotted blue line with a width of 1 pixel */
border-top: 1px dotted blue;

/* Set the top border to a double black line with a width of 3 pixels */
border-top: 3px double black;

The border-top property can also be used with other border properties to create more complex border styles. For example:


/* Set the top border to a solid red line with a width of 2 pixels, and the other borders to a dashed blue line with a width of 1 pixel */
border: 1px dashed blue;
border-top: 2px solid red;

/* Set the top border to a solid red line with a width of 2 pixels, and the bottom border to a dotted blue line with a width of 1 pixel */
border-top: 2px solid red;
border-bottom: 1px dotted blue;

Conclusion

The border-top property is a useful CSS property that allows developers to customize the appearance of an element's top border. By setting the width, style, and color of the top border, developers can create a wide range of border styles to suit their needs.

References

Activity