A border around an element often looks inconspicuous, but it noticeably changes the impact of a page. With the CSS property border, you can highlight HTML elements, separate them, or make them look like buttons. In this tutorial, you will learn how the property is structured, which styles are available, and how to style individual sides of an element in a targeted way.
All you need for this is a simple HTML page with an element, for example a colored div, and an editor of your choice. Try out each step directly in the code, so that what you learn sticks better.
Key Takeaways
- The
borderproperty consists of three values: width, style, and color. - The order of the values is flexible, but the usual notation is width, style, color.
- You can specify colors with names like
blackoryellowor with hexadecimal values like#cccccc. - The most important styles include
solid,dotted,dashed,double,groove,inset, andoutset. - With
border-top,border-bottom,border-left, andborder-right, you style individual sides. - The shorthand notation
border: 10px solid black;is the most common form in practice.
Step 1: Understanding the Basic Idea of a Border
Imagine a border as a line that runs around the outside of your element. In the video, you see a green-and-black element with a five-pixel-wide black border. Exactly this effect is created by a single CSS rule assigned to the element.

A look at the code shows you where the rule is located. There, the border property is defined and assigned values. This line completely determines the appearance and size of the border.

Step 2: Getting to Know the Three Components of the border Property
The border property is a so-called shorthand property. It combines three values in one line. First comes the thickness or width of the border, for example 5px. Next comes the type of border, that is, the style, such as solid. At the end comes the color, for example black.
A complete example looks like this: border: 5px solid black;. If you leave out one of these three values, the browser uses a default value. Therefore, make sure to specify at least the width and style so that the border is reliably visible.
Step 3: Defining Colors for the Border
You can specify the color in two ways. The simplest option is a color name like black, yellow, or grey. For finer gradations, hexadecimal values are suitable. Here, #cccccc stands for a darker shade of gray, while #00ff00 produces a bright green. With a little practice, you will recognize the color from the code.
Feel free to try out different hex values to get a feel for it. Even a small change to the last two digits shifts the hue significantly.
Step 4: Adjusting the Width of the Border
You specify the width in pixels. A value of 15px produces a much bolder border than 5px. The value is self-explanatory, so you should mainly pay attention to readability. A very wide border can visually overwhelm the content, while a thin border is hardly noticeable on some screens.
Step 5: Trying Out the Most Important Border Styles
The style determines what the line looks like. The value solid draws a continuous, single-colored line without effects. This is the default you need in most projects.
With dotted, you get a dotted border. With large widths, this quickly looks restless, so the thickness is reduced. In the example, the width was reduced to three pixels so that the dots remain clearly recognizable.
The value dashed draws a dashed border with elongated strokes. With double, two parallel lines appear next to each other. This looks particularly elegant with somewhat wider borders and stands out immediately.
Step 6: Using Decorative Styles like groove, inset, and outset
Some styles simulate a three-dimensional effect. With groove, the border appears slightly recessed, as if pressed into the surface. The styles inset and outset work similarly, but emphasize different directions. While outset makes the element look like a raised button, inset looks more like a depression.
To see the effect clearly, a larger width is worthwhile. At ten pixels, the button effect of outset becomes noticeable at first glance.
Other styles exist as well. You can find an overview by searching for "Border Style" in a search engine. There you can compare all the variants and try them out directly.
Step 7: Styling individual sides of an element
The border should not always run all the way around. With border-style you set the style for all sides, but you can also target just one side. To do this, you use border-top, border-bottom, border-left or border-right.

An example: With border-top, only the top edge gets a border. It is important that you not only set the color, but also specify the width and the style. Without these values, the border remains invisible, even if the color is correct.
In the video, the attempt initially fails because the property is misspelled. The correct name for the width of a single side is border-top-width. If a rule does not take effect, first check the spelling of the property.

Step 8: Using the shorthand notation for individual sides
In practice, you often combine the three values in one line. For a single side, you write, for example, border-top: 10px solid;. You can add the color so that the line reads in full: border-top: 10px solid black;.
In this way, other sides can also be styled quickly. With border-bottom, for example, the border moves to the bottom. For a complete outline, you can set all four sides individually or simply use the general border property.
For everyday use, I recommend the shorthand notation border: 10px solid black; for complete borders and the side-specific properties only when you want to deliberately highlight individual edges.
Summary – Setting CSS border: Styling borders with width, style and color
The border property is a versatile tool with which you can visibly highlight elements. You combine width, style and color in one line and thereby decide on the appearance. The styles range from simple lines like solid, through dots and dashes, to three-dimensional effects like outset. With the side-specific properties, you style individual edges precisely. Try out the examples yourself, and you will quickly understand how the values take effect.
FAQ
What are the three components of the border property?The three components are the width, the style and the color of the border, for example border: 5px solid black;
Can I change the order of the values in border?Yes, the order is freely selectable. However, the usual notation is width, style, color.
Which colors can I use for a border?You can use color names like black or yellow or hexadecimal values like #cccccc.
What does the style solid do?Solid draws a continuous, single-color line without any special effects.
Which styles create a three-dimensional impression?Groove, inset and outset look three-dimensional. Outset, for example, creates the impression of a raised button.
How do I set a border on only one side?You use border-top, border-bottom, border-left or border-right, for example border-top: 10px solid black;
Why is my side-specific border not displayed?Check whether width, style and color are specified and whether the property is spelled correctly, for example border-top-width instead of border-top with.
