qhtml.js About Info

What is qHTML.js?

qHTML is a simplified, custom representation of HTML designed for ease of reading and maintenance; its syntax resembles CSS but defines HTML structure and attributes inline. Because qHTML is implemented as a custom web component, you simply wrap your markup in a <q-html> element and it will transform into standard HTML without any boilerplate or JavaScript API. It’s also easy to extend by defining new custom components so you can reuse blocks with custom attributes.

How it works

A qHTML document looks like CSS: you write tag names followed by braces, and inside the braces you specify attributes and nested elements. Attributes are assigned using name: "value" pairs, and the content property (or synonyms like text or innertext) sets the inner text of an element. All valid HTML attributes work, including event handlers like onclick, and you can nest elements by declaring additional blocks inside braces.

For example:

<script src="qhtml.js"></script>
<q-html>
  div {
    id: "myDiv"
    class: "container"
    content: "click the button below for a special message"
    button {
      onclick: "alert('hello world')"
      content: "click me!"
    }
  }
</q-html>

When the page loads, the qHTML component generates the equivalent HTML:

<div id="myDiv" class="container">
  click the button below for a special message
  <button onclick="alert('hello world')">click me!</button>
</div>

qHTML also includes optional helpers like simplified nesting (write multiple tags separated by commas), custom components defined with <q-component>, and a <q-script> tag for adding event listeners in a concise syntax.
Check out the examples below for a couple of exmaples of features available in qHTML.

Why use qHTML instead of traditional HTML?

  • âś“Readable, CSS‑like syntax — qHTML uses a familiar, indentation‑friendly syntax so you spend less time closing tags and more time describing structure:.
  • âś“No boilerplate — because qHTML is a custom element, you don’t need to write JavaScript or import any APIs; drop your qHTML inside a <q-html> tag and it renders automatically.
  • âś“Easy extensibility — define new custom components with <q-component> and they become available with all their inline attributes.
  • âś“Nesting and attributes — all valid HTML attributes and event handlers work; you can nest elements naturally using braces.
  • âś“Scripting helper — qHTML provides a <q-script> tag to attach event listeners and write small scripts using CSS selector syntax.

Standard Usage, HTML, and Attributes

div { id: "myDiv" class: "container" span { html { You can inline HTML using the HTML tag } } span { text: "Or just use the text attribute to set text content" } br { } br { } span { html { you can use onclick attributes or q-script to add events } } br { } button { onclick: "alert('hello world')" content: "click me!" } }
You can inline HTML using the HTML tag Or just use the text attribute to set text-only

you can use onclick attributes or q-script to add events
You can inline HTML using the HTML tag Or just use the text attribute to set text-only

you can use onclick attributes or q-script to add events

q-components and combinators

prerequisites: q-html.js, w3.css

 
q-component { id: "menu-item" span { class: "w3-bar-item w3-blue w3-hover-grey" div { slot { name: "item-contents" } } } } div { class: "w3-bar w3-green" menu-item { div { slot: "item-contents" html { item 1 } } } menu-item { div { slot: "item-contents" div,a { href: "/" html { heres a link } } } } }

advanced combinators

prerequisites: q-html.js, w3-tags.js

 
q-component { id: "nav-button" w3-bar-item,w3-black,w3-btn,w3-hover-blue,span { slot { name: "button-contents"; } html { ➡️ } } } w3-main,w3-green,div { w3-bar-block,w3-grey,div { nav-button { span { slot: "button-contents" html { button 1 } } } nav-button { span { slot: "button-contents" html { button 2 } } } nav-button { span { slot: "button-contents" html { button 3 } } } } }
button 1 ➡️ button 2 ➡️ button 3 ➡️
button 1 ➡️ button 2 ➡️ button 3 ➡️

combining w3-tags.js

prerequisites: qhtml.js, w3-tags.js


Combine unlimited numbers of w3-tags with plain html tags to create complex layouts
Everytime you combine two  or more tags (separating them with a comma) , it creates a nested structure.  

div,span,div { }

is equivalent to

<div> 
    <span>
        <div>
        </div>
    </span>
</div>
 

 

 

 

w3-tags.js  creates a uniqe custom element definition for each of the w3-* CSS classes from the w3.css framework.

When you use the custom element tags, the result will be like this.

w3-main,w3-green,div { }

w3-main,w3-green,div,w3-blue,div { }

is equivalent to

<w3-main>
  <w3-green>
    <div>
    </div>
  </w3-green>
</w3-main>

<w3-main>
  <w3-green>
    <div>
      <w3-blue>
         <div>
         </div>
     </w3-blue>
    </div>
  </w3-green>
</w3-main>


Now w3-tags.js will transform nested w3-elements into their equivalent classes and apply them to the next non w3-element that appears in the hierarchy.

The above translates into this when all is said and done:

<div class="w3-main w3-green">
</div>

<div class="w3-main w3-green">
   <div class="w3-blue">
   </div>
</div>
 
w3-bar, w3-black, w3-text-white,div,w3-bar-item, w3-left { span { text: "Item1" } span { text: "item 2" } } w3-container, w3-large, w3-title, w3-header,w3-xlarge,w3-green,div { text: "Hello world" } w3-twothird,w3-article, w3-panel, w3-light-grey, blockquote, w3-justify,article,p { text: "Heres a great article about saying hello to the world. only the way everybody else does it -- by saying hello world... only in latin... " } w3-quarter, w3-nav, w3-col, w3-right, w3-padding,div,w3-list,w3-block,ul { w3-bar,w3-green,w3-bar-item { li { text: "navigation" } w3-black,w3-center,w3-bar-item { li { text: "item 1" } li { text: "item 2" } li { text: "item 3" } } } }
Item1 item 2
Hello world

Heres a great article about saying hello to the world. only the way everybody else does it -- by saying hello world... only in latin...

  • navigation
  • item 1
  • item 2
  • item 3
Item1 item 2
Hello world

Heres a great article about saying hello to the world. only the way everybody else does it -- by saying hello world... only in latin...

  • navigation
  • item 1
  • item 2
  • item 3

w3-tags chaining with multiple descendants

prerequisites:  qhtml.js,  w3-tags.js (or bs-tags.js)
         

When you use bs-tags (bootstrap tags) or w3-tags (w3.css tags), the w3-* and bs-* HTML tags support a way to pass along a set of classes to all of the direct descendants of a chain of tags. 
 

If you do not terminate a chain of w3-tags or bs-tags by putting a final regular HTML element at the end of the chain, but instead begin a block using the brackets. { },  Everything inside of the brackets will be treated as if it is the last part of the chain, whether that part is a regular HTML element or additional w3-tags (or bs-tags).
 

You can nest multiple unterminated chains to create complex CSS rules. 

w3-green,w3-large {
   w3-button,w3-hover-blue {
       w3-bar,span { text: "hello" }
       w3-bar,span { text: "world" }
   }
}

 Since there is no terminating HTML element for the first two nested chains, w3-tags will apply both of the chains to each span separately

 


  hello



 world
 
w3-green,w3-main,div { style: "min-height: 50vh;" span { html {

title area

} } w3-container,w3-bar-block,w3-blue,nav { header { html { navigation area } } style: "min-height: 50vh; max-width: 25vw;" w3-grey,w3-bar-item,w3-btn,w3-button { span,a { href: "#" html { Home } } span,a { href: "#about" html { About} } span,a { href: "#more" html { More} } } } }

title area

title area

More examples at https://qhtml.github.io/qhtml.js/