Toolvito

Works on this device

UI Component Generator

Choose a component and type its words and colours. The page writes the HTML and the plain CSS for it, with labels, a focus ring and checked contrast. No framework and no script is needed.

Choose and type the values

A button with a hover change and a focus ring, as a button element or as a link.

A hex colour, rgb(), hsl() or a colour name.

Your values are worked out in this browser. They are not sent to a server.

Your component will show here

Correct the values that are marked, and the result comes back.

How to use the generator

  1. Choose a component in the first menu.
  2. Type the words, the links and the colours. The sample and the code change as you type.
  3. Read the contrast figures in the result. A note tells you when a pair of colours is too close.
  4. Choose Copy under the HTML and under the CSS, or download the one page that holds both and open it in your browser.

The components

  • Button: a button element, or a link that looks like a button, filled or outlined, with a hover change.
  • Form field: a labelled field of the input type you choose: text, email, password, tel, url, number, search, date, time, or a textarea for several lines.
  • Navigation bar, breadcrumb path and pagination: lists of links inside a nav element, with the current page marked.
  • Card, alert and badge.
  • Tabs and parts that open: made with details elements, or with radio buttons, and no script.
  • Switch: a tick box that looks like a switch.
  • Image slider, image gallery and picture beside text.

Accessible by default

  • Every field has a label that is tied to it. Help text is tied to its field with aria-describedby.
  • Every link and button shows a clear ring when it has the keyboard focus (:focus-visible).
  • Navigation is a list of links in a nav element with a name. The current page has aria-current="page".
  • Roles are written only where they are needed: role="switch" on the switch, role="region" on the slider that scrolls, and role="status" or role="alert" on a message that a script adds later.
  • A message says its kind in words, such as "Warning:", and a switch shows on and off by the place of its knob. Nothing is told by colour alone.
  • The page works out the contrast of your colours with the WCAG formula and tells you when text is below 4.5 to 1, or a border or focus ring is below 3 to 1.
  • A change on hover is short and is turned off for people who ask their device for less motion.

Worked example

Choose Button and keep the main colour #1f5fa8 with white words. The contrast of the words on the button is 6.44 to 1, which is above the 4.5 to 1 that WCAG level AA asks for normal text.

For the hover change, each of the three colour values is multiplied by 0.85. #1f5fa8 is red 31, green 95, blue 168, and that gives 26, 81 and 143, which is #1a518f. White on that colour has a contrast of 8.02 to 1.

The result is <button class="btn" type="button">Send message</button> and a .btn rule with a .btn:hover and a .btn:focus-visible rule.

How the sample is made

The sample is built by this page from its own elements. Each value of the CSS is set on them one by one after a check, and the HTML and CSS text itself is never put into the page.

The page loads no picture, so a grey box with the alt text stands where a picture will be. Links in the sample do not leave the page. Choose Play to see how the links and buttons look when a pointer is over them.

The sample stands in a box that rolls back the styles of this site, so it looks as it would on an empty page with a plain system font.

Limits you should know

  • The tabs made of radio buttons are told by a screen reader as radio buttons, not as tabs. True tabs with the ARIA tab roles, a menu that opens with a button, a pop-up window and a slider with buttons need a script, and are not made here.
  • The image slider is moved by the visitor. Nothing moves by itself.
  • One component for each result, with class names that are fixed (.btn, .card, .nav ...). Change the names if your page already uses them.
  • The four alert colours and the border colours are fixed, so that their contrast is known. All other colours are yours, and a colour with opacity is refused because its contrast cannot be known.
  • The contrast figures are for the colours you typed. They do not know what stands behind the component in your page.
  • A table with styles is made by the HTML Table Generator, and a whole form by the HTML Element Generator.

Related tools