< Up a Level

Styling code-input elements with CSS

Contributors: 2025 Oliver Geer

General comments

code-input elements can be styled like textarea elements in most cases; however, there are some exceptions:

Please do not use className in JavaScript referring to code-input elements, because the code-input library needs to add its own classes to code-input elements for easier progressive enhancement. You can, however, use classList and style as much as you want - it will make your code cleaner anyway.

Highlighting theme requirements

code-input.js works with most highlighter themes from major syntax highlighting libraries. However, if you’re making your own theme or have problems please note:

/* Fixes most broken themes: */
pre code,
pre code * {
  font-family: inherit !important;
  font-size: inherit !important;
  letter-spacing: inherit !important;
  line-height: inherit !important;
}
pre code * {
    margin: 0px !important;
    border-width: 0px !important;
    padding: 0px !important;
}

/* If the theme uses a proportional font
rather than a monospace font, also include
this CSS: */
pre code,
pre code * {
  font-weight: inherit !important;
  font-style: inherit !important;
}

Methods of resizing

code-input elements default to having a fixed height and filling the width of their container while the code inside scrolls, and you can set the ordinary CSS properties (for example height and width) to change this size. You can also make the size more flexible using CSS:

A syntax-highlighted code input element with diagonal lines in the corner, which can be dragged to resize the element.