Skip to content

Commit e4050a5

Browse files
committed
Document boolean attributes
1 parent ccce68b commit e4050a5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

docs/source/basics.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,22 @@ Attribute values are quoted (HTML-escaped) automatically:
172172
>>> print(div(attr='a value with "quotes" and a <tag>'))
173173
<div attr="a value with &quot;quotes&quot; and a &lt;tag&gt;"></div>
174174

175+
Boolean attributes
176+
^^^^^^^^^^^^^^^^^^
177+
178+
A boolean HTML attribute is one that does not have a value. For example, to
179+
mark an input field as required, you can write ``<input required>``. There is
180+
also an alternative syntax, which minihtml uses: ``<input
181+
required="required">``.
182+
183+
To set a boolean attribute, pass ``True`` as the value. ``False`` is also a
184+
valid value, and causes the attribute to be omitted (this can be useful if you
185+
set the attribute from a variable):
186+
187+
>>> from minihtml.tags import input
188+
>>> print(input(required=True, disabled=False))
189+
<input required="required">
190+
175191
.. _content:
176192

177193
Content

0 commit comments

Comments
 (0)