Add rounded borders to a div element:
document.getElementById("myDIV").style.borderRadius = "25px";
Click the button to set the borderRadius property of the DIV element:
<!DOCTYPE html> <html> <head> <style> #myDIV {// w ww.j av a 2 s.c o m border: 1px solid black; width: 300px; height: 300px; } </style> </head> <body> <button onclick="myFunction()">Test</button> <div id="myDIV"> <h1>Hello</h1> </div> <script> function myFunction() { document.getElementById("myDIV").style.borderRadius = "25px"; } </script> </body> </html>
The borderRadius property is a shorthand property for setting, or getting, the four borderRadius properties.
The four border radius properties are (in this order):
The four values for each radii are given in the order top-left, top-right, bottom-right, bottom-left.
If bottom-left is omitted it is the same as top-right.
If bottom-right is omitted it is the same as top-left.
If top-right is omitted it is the same as top-left.
Property Values
Value | Description |
---|---|
length | Defines the shape of the corners. Default value is 0 |
% | Defines the shape of the corners in % |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The borderRadius property returns a String, representing the border-radius property of an element.