Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8864549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:16:03+00:00 2026-06-14T16:16:03+00:00

How to set border-width of an element in percentages? I tried the syntax border-width:10%;

  • 0

How to set border-width of an element in percentages? I tried the syntax

border-width:10%;

But it doesn’t work.

The reason I want to set border-width in percentages is I have an element with width: 80%; and height: 80%;, and I want the element to cover the whole browser window, so I want to set all borders 10%. I am not doing this with the two elements method, in which one would be positioned behind the other and act as the border, because the element’s background is transparent, and positioning an element behind it would affect it’s transparency.

I know this can be done via JavaScript, but I am looking for an CSS only method, if possible at all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:16:04+00:00Added an answer on June 14, 2026 at 4:16 pm

    Border doesn’t support percentage… but it’s still possible…

    As others have pointed to CSS specification, percentages aren’t supported on borders:

    'border-top-width',
    'border-right-width',
    'border-bottom-width',
    'border-left-width'
      Value:          <border-width> | inherit
      Initial:        medium
      Applies to:     all elements
      Inherited:      no
      Percentages:    N/A
      Media:          visual
      Computed value: absolute length; '0' if the border style is 'none' or 'hidden'
    

    As you can see it says Percentages: N/A.

    Non-scripted solution

    You can simulate your percentage borders with a wrapper element where you would:

    1. set wrapper element’s background-color to your desired border colour
    2. set wrapper element’s padding in percentages (because they’re supported)
    3. set your elements background-color to white (or whatever it needs to be)

    This would somehow simulate your percentage borders. Here’s an example of an element with 25% width side borders that uses this technique.

    HTML used in the example

    .faux-borders {
        background-color: #f00;
        padding: 1px 25%; /* set padding to simulate border */
    }
    .content {
        background-color: #fff;
    }
    <div class="faux-borders">
        <div class="content">
            This is the element to have percentage borders.
        </div>
    </div>

    Issue: You have to be aware that this will be much more complicated when your element has some complex background applied to it… Especially if that background is inherited from ancestor DOM hierarchy. But if your UI is simple enough, you can do it this way.

    Scripted solution

    @BoltClock mentioned scripted solution where you can programmaticaly calculate border width according to element size.

    This is such an example with extremely simple script using jQuery.

    var el = $(".content");
    var w = el.width() / 4 | 0; // calculate & trim decimals
    el.css("border-width", "1px " + w + "px");
    .content { border: 1px solid #f00; }
    <div class="content">
        This is the element to have percentage borders.
    </div>

    But you have to be aware that you will have to adjust border width every time your container size changes (i.e. browser window resize). My first workaround with wrapper element seems much simpler because it will automatically adjust width in these situations.

    The positive side of scripted solution is that it doesn’t suffer from background problems mentioned in my previous non-scripted solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried to set the margin and border to 0,but still not working. <style
I have an img element set next to a div. I have tried a
I need to calculate the width of an element's border. If I set it
I'm attempting to get the width of an element's border with $('#foo').css('border-width-bottom') , but
I am styling a asp:DropDownList element with custom CSS. I have set the height
Essentially I want a border-less, black window which I can set the location and
I have follwoing HTML <div style=border: 1px solid;> <div style=background-color: blue; width: 1200px;> <h3>
i want set width for PdfpCell in Table, i want design this i Write
I have a hr element that's inside a div setting width to %50 .
I have an image that I'd like to set as the border on an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.