CSS Border
button {
border: 2px solid white;
}
input {
border: 2px solid #cccccc;
}
Let me ask you something.
Have you ever seen a card on a website with a clean thin line around it? Or an input field with a subtle border that turns a different color when you click it? Or a section with a bold line on the left side making it stand out?
All of that is border. It is one of those properties that seems simple on the surface but gives you a surprising amount of creative control once you know how to use it.
What is a Border
A border is a line that goes around the outside of an element. It sits between the padding and the margin.
In CSS you set a border using three things together — the width, the style, and the color.
The button now has a 2px solid white border around it.
Let us break that down.
2px— how thick the border issolid— the style of the linewhite— the color of the border
All three values go together in one line separated by spaces. This is the shorthand and it is what you will use almost every time.
Border Styles
The style is what controls what the line actually looks like. There are several options.
solid border
dashed border
dotted border
double border
.solid { border: 2px solid black; padding: 8px; } .dashed { border: 2px dashed black; padding: 8px; } .dotted { border: 2px dotted black; padding: 8px; } .double { border: 4px double black; padding: 8px; }Four different styles, four very different looks. In real projects you will use solid almost
exclusively. Dashed and dotted occasionally for things like dividers or upload zones. Double almost never.
If you write a border without a style it will not show up at all. The style is required.
border: 2px white will not work. You need border: 2px solid white. The style is the one
value beginners most often forget.
Border on Individual Sides
You can put a border on just one side of an element instead of all four. This is really useful for creating subtle dividers or left-side accent lines.
Border on top only
Border on left only
Border on bottom only
.top { border-top: 2px solid black; padding: 8px; } .left { border-left: 4px solid #E50914; padding: 8px; } .bottom { border-bottom: 1px solid #cccccc; padding: 8px; }That left border on the second paragraph is a pattern you will see everywhere in modern design. A thick colored line on the left side of a block of text creates a clean visual accent that draws the eye without being heavy handed.
A single border-bottom on a navigation bar is one of the most common design patterns in web
development. It creates a clean separator between the nav and the content below without feeling heavy. Try
border-bottom: 1px solid rgba(255,255,255,0.1) on a dark navbar for a subtle professional look.
Border Color
You can set the border color separately if you want to change just the color without touching the other values.
First we set the full border then we override just the color. You will use this pattern when you want to change the border color on hover or focus — which we will cover in the pseudo-classes lesson.
Removing a Border
Sometimes you want to remove a border completely. The most common case is removing the default border that browsers put on input fields and buttons.
Clean. No border at all. You will use border: none constantly on buttons and inputs when you want to
style them from scratch without fighting the browser defaults.
Browsers add default borders to input fields and buttons. One of the first things most developers do when styling
a form is write border: none on the inputs and buttons to strip those defaults away and start fresh.
Then they add back exactly the border they want.
Border Width
You can also set the border width separately using border-width. It works exactly like padding and
margin — one value for all sides or up to four values for each side individually.
Unlimited movies, TV shows, and more.
Thin border on three sides and a thick border on the bottom. That asymmetry creates a subtle but interesting visual effect.
Building the Netflix Clone
Let us add some borders to our Netflix clone. The input field needs a border and we should style the Sign In button differently from the Get Started button — one filled and one outlined.
Netflix
Unlimited movies, TV shows, and more.
Starts at USD 2.99. Cancel anytime.
Ready to watch? Enter your email to create or restart your membership.
* { margin: 0; padding: 0; } body { font-family: "Roboto", Arial, sans-serif; font-size: 16px; padding: 40px; background-image: linear-gradient(to bottom, rgba(0,0,0,0.7), rgba(0,0,0,0.4)), url("https://assets.nflxext.com/ffe/siteui/vlv3/9ba9f0e2-b246-47f4-bd1f-3e84c23a5db8/web/NP-en-20251020-TRIFECTA-perspective_774f89dc-b75d-4cfc-b1fe-52086741fae3_large.jpg"); background-size: cover; background-position: center; background-repeat: no-repeat; text-align: center; } #logo { font-family: "Bebas Neue", sans-serif; font-size: 3rem; font-weight: 700; color: #E50914; letter-spacing: 4px; line-height: 1; margin-bottom: 16px; } h1 { font-family: "Bebas Neue", sans-serif; font-size: 3rem; font-weight: 700; color: white; letter-spacing: 2px; line-height: 1.2; margin: 60px 0 16px 0; } p { font-size: 1.1rem; font-weight: 300; color: white; line-height: 1.6; margin-bottom: 12px; } button { background-color: #E50914; color: white; font-size: 1rem; font-weight: 600; text-transform: uppercase; letter-spacing: 2px; padding: 12px 32px; margin-top: 24px; border: none; } .signin { background-color: transparent; border: 2px solid white; color: white; font-size: 0.9rem; font-weight: 600; padding: 8px 20px; margin-top: 0; } input { border: 2px solid #cccccc; padding: 12px 16px; font-size: 1rem; }The Get Started button is solid red with no border. The Sign In button is transparent with a white outline border — a classic ghost button style used everywhere in modern design. The input field has a clean subtle border. Everything feels intentional and designed.
Have anything to say about this lesson?
Your feedback helps improve these tutorials. If something was confusing or missing, let us know.