Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

CSS Borders: How to Style Element Borders

Set visible CSS borders by specifying a line style, then customize their width, color, sides, corners, and effect on element dimensions.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the CSS border shorthand to set an element’s border width, line style, and color: border: 1px solid #333;. The line style is essential: if it is omitted, the style defaults to none, so a declared width and color alone will not display a border.

Set a border on all four sides

The border shorthand applies to the top, right, bottom, and left sides. It accepts width, style, and color in any order:

.card {
  border: 1px solid #333;
}

Here, 1px is the width, solid is the line style, and #333 is the color. The width and color are optional when a style is provided: an omitted width defaults to medium, and an omitted color defaults to currentColor. But if you omit the style, it defaults to none, and the border is not drawn. See MDN’s border reference.

Choose a line style and set different sides

Common values for border-style include solid, dotted, dashed, double, groove, ridge, inset, and outset. For example, a card can have a solid top edge and a dashed bottom edge:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
.card {
  border-top: 2px solid #333;
  border-bottom: 1px dashed #999;
}

Side shorthands such as border-top set width, style, and color for that side. You can also use individual properties such as border-top-width, border-top-style, and border-top-color. For logical, writing-direction-aware sides, use properties such as border-inline-start.

Use one to four values for all side styles

The number of values in border-style determines how they map to sides:

  • One: all four sides.
  • Two: top and bottom, then left and right.
  • Three: top, left and right, then bottom.
  • Four: top, right, bottom, left.
.card {
  border-style: solid dashed dotted double;
}

In that example, the sides are solid, dashed, dotted, and double in clockwise order. The exact dash-segment length and dot spacing are not specified, so their appearance can vary by browser. For property details, see MDN’s border-style reference.

Round corners with border-radius

Set border-radius to round all corners, or provide multiple values to control corners individually:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
.card {
  border: 1px solid #ccc;
  border-radius: 8px;
}

Lengths and percentages are supported. A single radius applies to all corners; multiple radii allow different corners, and elliptical radii can use separate horizontal and vertical values. For percentage radii, the horizontal component is relative to the box width and the vertical component to its height. See MDN’s border-radius reference.

Understand how borders affect element size

A border sits between padding and margin. Whether it adds to the element’s outside dimensions depends on box-sizing:

  • With the standard content-box model, declared width and height describe the content box. Border thickness adds to the outside dimensions, along with padding.
  • With border-box, the declared width and height include the content, padding, and border. A thicker border uses more of those declared dimensions instead of expanding the outside size.

If adding a border unexpectedly changes a layout, check the element’s computed box-sizing as well as its width and padding. The box-model explanation is in MDN’s CSS box model guide.

Choose between a border and an outline

A border is part of the box and affects its dimensions. An outline is drawn outside the border and does not take up layout space, which makes it useful for showing keyboard focus without shifting nearby content. Outlines are not necessarily rectangular in every case.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
a:focus-visible {
  outline: 3px solid #1769aa;
  outline-offset: 3px;
}

Do not remove an interactive element’s focus outline with outline: none or outline: 0 unless you provide an equally obvious visible focus treatment. See MDN’s outline reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot a border that does not appear

  • Check the style first. A declaration such as border: 2px #333 leaves the style at none. Add one, for example border: 2px solid #333.
  • Check the selector and cascade. Confirm the rule matches the intended element and that another rule does not override its border or border style.
  • Check side-specific declarations. A later shorthand or longhand can change the side you are trying to show. Inspect the computed styles in your browser’s developer tools.
  • Check visibility and color. Verify the element is rendered and that the border color contrasts with its background.
  • Check box sizing if dimensions changed. The border may be visible but enlarge an element using the standard content-box model.

Or skip the browser setup

For a rendered page screenshot, ScreenshotNeo takes a screenshot with one GET request. For example, this cURL command saves the result as a WebP file:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Before capture, it accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server offers screenshot and page-info tools for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.