HTML Basic
HTML Reference
- HTML Tags
- HTML Deprecated Tags
- HTML Events
- HTML Attributes
- accept
- accept-charset
- accesskey
- action
- align
- alt
- as
- async
- autocomplete
- autofocus
- autoplay
- bgcolor
- border
- charset
- checked
- cite
- class
- color
- cols
- colspan
- content
- contenteditable
- controls
- coords
- data
- data-*
- datetime
- default
- defer
- dir
- dirname
- disabled
- download
- draggable
- enctype
- enterkeyhint
- for
- form
- formaction
- headers
- height
- hidden
- high
- href
- hreflang
- http-equiv
- id
- inert
- inputmode
- ismap
- kind
- label
- lang
- list
- loop
- low
- max
- maxlength
- media
- method
- min
- multiple
- muted
- name
- novalidate
- onabort
- onafterprint
- onbeforeprint
- onbeforeunload
- onblur
- oncanplay
- oncanplaythrough
- onchange
- onclick
- oncontextmenu
- oncopy
- oncuechange
- oncut
- ondblclick
- ondrag
- ondragend
- ondragenter
- ondragleave
- ondragover
- ondragstart
- ondrop
- ondurationchange
- onemptied
- onended
- onerror
- onfocus
- onhashchange
- oninput
- oninvalid
- onkeydown
- onkeypress
- onkeyup
- onload
- onloadeddata
- onloadedmetadata
- onloadstart
- onmousedown
- onmousemove
- onmouseout
- onmouseover
- onmouseup
- onmousewheel
- onoffline
- ononline
- onpagehide
- onpageshow
- onpaste
- onpause
- onplay
- onplaying
- onpopstate
- onprogress
- onratechange
- onreset
- onresize
- onscroll
- onsearch
- onseeked
- onseeking
- onselect
- onstalled
- onstorage
- onsubmit
- onsuspend
- ontimeupdate
- ontoggle
- onunload
- onvolumechange
- onwaiting
- onwheel
- open
- optimum
- pattern
- placeholder
- popover
- popovertarget
- popovertargetaction
- poster
- preload
- readonly
- rel
- required
- reversed
- rows
- rowspan
- sandbox
- scope
- selected
- shape
- size
- sizes
- span
- spellcheck
- src
- srcdoc
- srclang
- srcset
- start
- step
- style
- tabindex
- target
- title
- translate
- type
- usemap
- value
- width
- wrap
- HTML Global Attributes
- HTML Status Code
- HTML Language Code
- HTML Country Code
- HTML Charset
- MIME Types
HTML border Attribute
Photo Credit to CodeToFun
🙋 Introduction
The border
attribute in HTML is a fundamental element used to define the border properties of an HTML element, primarily applicable to table elements.
It allows developers to specify the width, style, and color of the border surrounding an element.
🎯 Purpose of border
The primary purpose of the border
attribute is to provide a visual distinction for HTML elements.
It is commonly used to outline tables, images, and other elements on a webpage, enhancing the overall layout and design.
💎 Values
The border
attribute accepts three values to define different aspects of the border:
- Width: Specifies the width of the border. It can be set in pixels, em units, or as a percentage of the element's width.
- Style: Defines the style of the border. Common styles include solid, dashed, dotted, double, and more.
- Color: Sets the color of the border. You can use color names, hexadecimal values, RGB values, or other valid color representations.
📄 Example
Let's look at an example of how to use the border
attribute in an HTML table:
<table border="1">
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
🧠 How it Works
In this example, the border
attribute is set to 1, indicating that a border with a width of 1 pixel should be applied to the entire table.
🔄 Dynamic Values with JavaScript
You can dynamically set the border
attribute using JavaScript.
This can be useful when you want to change the border properties based on user interactions or certain conditions. Here's a brief example:
<script>
// Dynamically set border properties for an element
document.getElementById("dynamicElement").style.border = "2px solid #3498db";
</script>
🧠 How it Works
In this script, the border
attribute is dynamically set to a 2-pixel solid border with the color #3498db for an element with the id dynamicElement.
🏆 Best Practices
- Use the
border
attribute judiciously, considering the design requirements of your webpage. - Experiment with different combinations of width, style, and color to achieve the desired visual effect.
- For more complex border requirements, consider using CSS for a finer level of control and flexibility.
🎉 Conclusion
The border
attribute is a valuable tool for defining the visual appearance of borders around HTML elements.
By understanding and using this attribute appropriately, you can create visually appealing and well-defined layouts on your webpages.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (HTML border Attribute), please comment here. I will help you immediately.