CSS border-top property

CSS border-top property is used to specify top side border width, style, and color of a HTML Element.

CSS border-top property is a shorthand to specify border-top-width, border-top-style, and border-top-color as a single property.

The syntax to specify border-top is

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

where

PropertyMandatory/OptionalExamples
border-top-widthOptional1px, 2em
border-top-styleMandatorysolid, dotted, double
border-top-colorOptional#555, red, #55fffcdd

Examples

ADVERTISEMENT

border-top: 5px solid red;

In the following example, we set a border-top for <h1> element, with border-top-width of 5px, border-top-style of solid, and border-top-color of red.

index.html

border-top: 5px solid;

In the following example, we set a border-top for <h1> element, with border-top-width of 5px, and border-top-style of solid. We do not specify any value for border-top-color.

index.html

border-top: solid;

In the following example, we set a border-top for <h1> element, with border-top-style of solid. We do not specify any width and color for the border-top.

index.html

div border-top

In the following example, we set a border-top for <div> element, with border-top value of 5px solid #00F.

index.html

Conclusion

In this CSS Tutorial, we learned about border-top property, and how to use this property for HTML Elements, with examples.