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

Every time 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

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

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

notice how every html element that doesn't start with w3- becomes the element where the w3-* classes all get applied to.

 
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
More examples at https://qhtml.github.io/qhtml.js/