Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="content-container">
  <header>
    <h1>Logical CSS</h1>
    <h2>Multi-Direction Support</h2>
  </header>
  <main>
    <p>Logical and Defensive CSS have similar goals. Each strive to make our UIs resilient across a dynamic range of users. Defensive CSS focuses on the variable nature of content while Logical CSS redefines the CSS box model to support a growing intersection of users, devices and cultures.</p>

    <fieldset>
      <legend>Toggle the content direction</legend>
      <label>
        <input checked id="direction-toggle-ltr" type="radio" name="direction" value="ltr" onChange={toggleContentDirection(this)} />
        <span>Left-to-Right</span>
      </label>
      <label>
        <input id="direction-toggle-rtl" type="radio" name="direction" value="rtl" onChange={toggleContentDirection(this)} />
        <span>Right-to-Left</span>
      </label>
    </fieldset>

    <div class="content-section" id="content-section">
      <section class="demo">
        <h3>Without Logical CSS</h3>
        <div class="demo-content-container">
          <img alt="A white and red cartoon spaceship flying through a blue sky of white stars" class="demo-image" src="https://img.freepik.com/premium-vector/rocket-flying-space-cartoon-vector-icon-illustration-transportation-technology-icon-isolated_138676-4368.jpg?w=2000" />
          <p class="demo-content">In a galaxy far, far away, a spaceship named Starblazer raced through the cosmos, its engines blazing with the power of a thousand suns. Piloted by a fearless crew of aliens and humans, it was on a mission to save their planet from destruction at the hands of an evil space tyrant. With laser cannons blazing and shields at full power, Starblazer engaged the enemy fleet in a fierce battle, determined to emerge victorious and save their world.</p>
        </div>
      </section>

      <section class="demo">
        <h3>With Logical CSS</h3>
        <div class="demo-content-container">
          <img alt="A white and red cartoon spaceship flying through a blue sky of white stars" class="demo-image" src="https://img.freepik.com/premium-vector/rocket-flying-space-cartoon-vector-icon-illustration-transportation-technology-icon-isolated_138676-4368.jpg?w=2000" />
          <p class="demo-content-logical">In a galaxy far, far away, a spaceship named Starblazer raced through the cosmos, its engines blazing with the power of a thousand suns. Piloted by a fearless crew of aliens and humans, it was on a mission to save their planet from destruction at the hands of an evil space tyrant. With laser cannons blazing and shields at full power, Starblazer engaged the enemy fleet in a fierce battle, determined to emerge victorious and save their world.</p>
        </div>
      </section>
    </div>
  </main>
  <footer>
    <p>Linting Defensive & Logical CSS With Stylelint Plugins</p>
    <a href="https://twitter.com/DanielYuschick" aria-label="@Daniel Yuschick on Twitter">@DanielYuschick</a>
  </footer>
</div>
              
            
!

CSS

              
                html {
  writing-mode: horizontal-tb;
}

.demo-content-container {
  display: flex;
  align-items: center;
}

.demo-image {
  inline-size: clamp(100px, 100%, 250px);
}

.demo-content {
  padding-left: 1rem;
  border-left: 1px solid var(--color-aux-100);
  margin-left: 1rem;
  max-width: 90ch;
  text-align: left;
}

.demo-content-logical {
  padding-inline-start: 1rem;
  border-inline-start: 1px solid var(--color-aux-100);
  margin-inline-start: 1rem;
  max-inline-size: 90ch;
  text-align: start;
}

/**********
*** SETUP
**********/
/***** Properties *****/
:root {
  --color-aux-50: rgb(10, 10, 11);
  --color-aux-100: rgb(29, 29, 32);
  --color-aux-200: rgb(48, 48, 54);
  --color-aux-300: rgb(77, 77, 86);
  --color-aux-400: rgb(96, 96, 108);
  --color-aux-500: rgb(115, 115, 130);
  --color-aux-600: rgb(147, 147, 159);
  --color-aux-700: rgb(169, 169, 178);
  --color-aux-800: rgb(190, 190, 197);
  --color-aux-900: rgb(223, 223, 226);
  --color-aux-950: rgb(242, 239, 233);

  --color-core-primary: #754abc;
  --color-core-secondary: #8b3257;

  --font-family-body: "Poppins", sans-serif;
  --font-family-heading: "Roboto Slab", serif;

  --space-base: 4px;
  --space-base-half: calc(var(--space-base) / 2);
  --space-base-1x: var(--space-base);
  --space-base-2x: calc(var(--space-base) * 2);
  --space-base-3x: calc(var(--space-base) * 3);
  --space-base-4x: calc(var(--space-base) * 4);
  --space-base-6x: calc(var(--space-base) * 6);
  --space-base-8x: calc(var(--space-base) * 8);
  --space-base-12x: calc(var(--space-base) * 12);
  --space-base-16x: calc(var(--space-base) * 16);
  --space-base-24x: calc(var(--space-base) * 24);
}

/***** Landmarks *****/
body {
  background-image: linear-gradient(
    160deg,
    hsl(335deg 47% 52%) 0%,
    hsl(335deg 47% 50%) 11%,
    hsl(335deg 47% 48%) 22%,
    hsl(335deg 47% 47%) 33%,
    hsl(335deg 47% 45%) 44%,
    hsl(335deg 47% 44%) 56%,
    hsl(335deg 47% 42%) 67%,
    hsl(335deg 47% 40%) 78%,
    hsl(335deg 47% 39%) 89%,
    hsl(335deg 47% 37%) 100%
  );
  padding: 1rem;
  text-wrap: balance;
}

main {
  max-inline-size: 100vw;
  overflow: hidden;
}

footer {
  --padding-offset: var(--space-base-4x);

  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  border-block-start: 1px solid var(--color-aux-50);
  padding-block: var(--padding-offset);
  margin-block-start: var(--padding-offset);
}

/***** Textual *****/
a,
a:visited,
a:active,
a:link {
  color: var(--color-core-secondary);
}

span,
p {
  font-family: var(--font-family-body);
}

p + p {
  margin-block-start: 1rem;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-family-heading);
}

code {
  background: var(--color-aux-100);
  color: var(--color-aux-950);
  display: block;
  padding: 0.25rem 0.5rem;

  &.inline {
    display: inline-block;
  }
}

/***** Other *****/
.content-container {
  inline-size: 75%;
  margin-inline: auto;
}

/**********
*** RESET
**********/
* {
  margin: 0;
  padding: 0;
}

*,
::before,
::after {
  box-sizing: border-box;
}

*:where(:not(fieldset, progress, meter)) {
  background-origin: border-box;
  border-style: solid;
  border-width: 0;
}

html {
  -webkit-text-size-adjust: none;
  block-size: 100%;
}

@media (prefers-reduced-motion: no-preference) {
  html:focus-within {
    scroll-behavior: smooth;
  }
}

body {
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-block-size: 100%;
  text-rendering: optimizeSpeed;
}

:where(img, svg, video, canvas, audio, iframe, embed, object) {
  display: block;
}
:where(img, svg, video) {
  block-size: auto;
  max-inline-size: 100%;
}

:where(svg) {
  fill: currentColor;
  stroke: none;
}

:where(svg):where(:not([fill])) {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke: currentColor;
}

:where(svg):where(:not([width])) {
  inline-size: 5rem;
}

:where(input, button, textarea, select),
:where(input[type="file"])::-webkit-file-upload-button {
  color: inherit;
  font-size: inherit;
  font: inherit;
  letter-spacing: inherit;
  word-spacing: inherit;
}

:where(textarea) {
  resize: block;
}

:where(span, p, h1, h2, h3, h4, h5, h6) {
  overflow-wrap: break-word;
  max-inline-size: 90ch;
}

:where(ul, ol) {
  list-style-position: inside;
}

:where(ul, ol, [role="list"]) {
  list-style: none;
}

:where(ul, ol, [role="list"]) li::before {
  border: 0px;
  clip: rect(0px, 0px, 0px, 0px);
  content: "\\200B";
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0px;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

a:not([class]) {
  text-decoration-skip-ink: auto;
}

:where(a[href], area, button, input, label[for], select, summary, textarea, [tabindex]:not([tabindex*="-"])) {
  cursor: pointer;
  touch-action: manipulation;
}
:where(input[type="file"]) {
  cursor: auto;
}
:where(input[type="file"])::-webkit-file-upload-button,
:where(input[type="file"])::file-selector-button {
  cursor: pointer;
}

@media (prefers-reduced-motion: no-preference) {
  :focus-visible {
    transition: outline-offset 145ms cubic-bezier(0.25, 0, 0.4, 1);
  }
  :where(:not(:active)):focus-visible {
    transition-duration: 0.25s;
  }
}
:where(:not(:active)):focus-visible {
  outline-offset: 5px;
}

:where(button, button[type], input[type="button"], input[type="submit"], input[type="reset"]),
:where(input[type="file"])::-webkit-file-upload-button,
:where(input[type="file"])::file-selector-button {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  text-align: center;
  user-select: none;
}

:where(button, button[type], input[type="button"], input[type="submit"], input[type="reset"])[disabled] {
  cursor: not-allowed;
}

/**********
*** UTILITIES
**********/
.content-container {
  min-block-size: calc(100vb - 2rem);
  inline-size: 100%;
  max-inline-size: 100vi;
  overflow: hidden;
  background-color: var(--color-aux-950);
  border: 1px solid bvar(--color-core-primary);
  border-radius: 4px;
  padding: 0 2rem;
  display: grid;
  grid-template-rows: min-content 1fr min-content;
}

.content-section {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-base-8x);
  align-items: start;
  padding-block: var(--space-base-8x);
  justify-content: space-between;
  overflow: hidden;
  max-inline-size: 100vi;

  &[dir="ltr"] {
    direction: ltr;
  }

  &[dir="rtl"] {
    direction: rtl;
  }
}

.demo {
  inline-size: max(calc(50% - var(--space-base-8x)), 500px);
}

fieldset {
  background-color: var(--color-aux-900);
  display: flex;
  gap: var(--space-base-6x);
  align-items: center;
  inline-size: max(calc(50% - var(--space-base-8x)), 500px);
  margin-block-start: var(--space-base-6x);

  legend {
    font-weight: 600;
  }
}

              
            
!

JS

              
                function toggleContentDirection(event) {
  const container = document.getElementById("content-section");
  container.setAttribute("dir", event.value);
}

              
            
!
999px

Console