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 rules Attribute
Photo Credit to CodeToFun
🙋 Introduction
The rules
attribute in HTML is used with <table> elements to specify which internal borders should be displayed within the table.
This attribute provides greater control over the appearance of table borders, enhancing the visual presentation of tabular data.
🎯 Purpose of rules
The primary purpose of the rules
attribute is to define the rendering of borders between rows, columns, or groups of both within a table. This allows for a more refined and customizable table layout, which can be particularly useful for creating complex tables with clear separations.
💎 Values
The rules
attribute accepts several values, each dictating different border behaviors:
- none: No internal borders are displayed. This is the default value if the
rules
attribute is not specified. - groups: Borders are displayed between row groups and column groups only.
- rows: Borders are displayed between rows only.
- cols: Borders are displayed between columns only.
- all: Borders are displayed between all rows and columns.
📄 Implementation Example:
Here's an example of how to use the rules
attribute in an HTML table:
<table rules="rows">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>30</td>
</tr>
<tr>
<td>Jane</td>
<td>25</td>
</tr>
</tbody>
</table>
🧠 How it Works
In this example, the rules
attribute is set to "rows", which means borders will be displayed between rows only.
🔄 Dynamic Values with JavaScript
You can dynamically set or change the rules
attribute using JavaScript. This is particularly useful when the table's border display needs to be modified based on user interaction or other conditions. Here's an example:
<script>
// Dynamically set rules for a table
document.getElementById("dynamicTable").rules = "cols";
</script>
🧠 How it Works
In this script, the rules
attribute is set to "cols" for a table element with the id "dynamicTable". This changes the table to display borders between columns only.
🏆 Best Practices
- Use the
rules
attribute to enhance the readability and organization of your tables, especially when displaying complex data. - Combine the
rules
attribute with CSS for more advanced styling and control over the table's appearance. - Test the table display across different browsers to ensure consistent rendering, as browser support for the
rules
attribute may vary.
🎉 Conclusion
The rules
attribute is a useful tool for controlling the internal borders of HTML tables.
By understanding and using this attribute effectively, you can create well-organized and visually appealing tables that improve the presentation of your data.
👨💻 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 rules Attribute), please comment here. I will help you immediately.