Skip to main content

CSS Border - Individual Sides

You can set a different border for each side of an element.

CSS has separate properties for each side: border-top-style, border-right-style, border-bottom-style, and border-left-style.

You can get the same result with the shorthand border-style property, which takes one to four values:

  • Four values (dotted solid double dashed): top, right, bottom, left.
  • Three values (dotted solid double): top, then right and left, then bottom.
  • Two values (dotted solid): top and bottom, then right and left.
  • One value (dotted): all four sides.

This also works with border-width and border-color.

Individual side properties

Each side is set with its own property.

Prompt
An HTML page that styles each border side separately. In an internal <style> block, style a paragraph with border-top-style dotted, border-right-style solid, border-bottom-style dotted, and border-left-style solid. Add a paragraph to show it.
Output: complete HTML page

Shorthand with two values

The shorthand border-style: dotted solid gives the same result.

Prompt
An HTML page that gets the same per-side result using the border-style shorthand. In an internal <style> block, give a paragraph border-style "dotted solid" so the top and bottom are dotted and the left and right are solid. Add a paragraph to show it.
Output: complete HTML page

One to four values

The number of values changes which sides get which style.

Prompt
An HTML page that shows how border-style behaves with four, three, two, and one value. In an internal <style> block, make four paragraph classes: "dotted solid double dashed", "dotted solid double", "dotted solid", and "dotted". Add a labeled paragraph for each so the difference is clear.
Output: complete HTML page