Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <main>
    <h1>Window Splitter</h1>
    <p>A window splitter allows you to resize two parts of a webpage.</p>
    <section class="split">
        <aside id="toc">
            <div>
                <h2 id="toc-title">Table of Contents</h2>
                <ul>
                    <li><a href="#start">Beginning</a></li>
                    <li><a href="#somewhere">Somewhere after the beginning</a></li>
                    <li><a href="#somewhere-else">Near the end</a></li>
                    <li><a href="#end">The end</a></li>
                </ul>
            </div>
        </aside>
        <div role="separator"
                aria-controls="toc"
                aria-labelledby="toc-title"
                aria-valuenow="34"
                aria-valuemin="0"
                aria-valuemax="100"
                tabindex="0">
            <span class="icon"></span>
        </div>
        <article>
            <h2>Enshrining Accessibility at Every Level</h2>

            <p>
              When I started to learn HTML, I began with basic elements like <code>h1</code>, <code>p</code>, <code>div</code>, and <code>button</code>.
              I learned about semantics, creating sections with headings, and styling elements with CSS.
              Unconsciously, I was laying a foundation of knowledge on how to build accessible websites.
              When I began specialising in accessibility, this foundation made it much easier for me to grasp a lot of the web accessibility guidelines and rules—I already knew how to apply most of them.
            </p>

            <p>
                In 2014—eight years in as a front-end developer—I attended a talk by Heydon Pickering in which he mentioned accessibility.
                This is when I realised that semantics play an important role in accessibility.
                Before that talk, I had only written semantic HTML because that’s what I had learned to do.
                Looking back, I now realise that it shouldn’t have taken eight years before I learned about something as important as accessibility.
            </p>

            <p>
                In those eight years, I read a lot of articles about various web-related topics.
                I don’t remember accessibility being a prominent part of those articles.
                This is something that most certainly has improved since then—a lot of articles now explicitly mention accessibility. That’s so cool!
            </p>

            <p>
                We all play our part in the accessibility of content.
                So we should all have some accessibility knowledge that relates to our part of the puzzle.
                From media managers that make sure the videos have subtitles to developers that know when to use ARIA and when not to.
                This also includes the people in charge of projects, such as product owners, department heads, and CEOs.
                These are the people that actually have the power to make accessibility a project requirement and establish it as a goal that everyone has to work towards.
            </p>

            <p>
                It’s difficult to be the only person who fights for accessibility.
                And we shouldn’t have to fight.
                The reason that we have to is that our superiors either don’t know about accessibility or don’t care about it.
                If only one person fights for accessibility, it’ll remain a personal thing—it won’t become a part of a companies design process.
                On top of that, there are a lot of different aspects to accessibility, and you cannot expect one person to know all the ins and outs.
                One specialist per company isn’t enough to create an accessible product.
            </p>

            <p>
                Every member of the team should be fully behind accessibility.
                The same way that the team should be fully behind delivering a quality product.
                After all, accessibility is a big part of the quality of your website.
            </p>

            <p>
                Accessibility gets increasingly more attention.
                We need to make sure that people in the right places know about it.
            </p>
        </article>
    </section>
</main>
              
            
!

CSS

              
                [role="separator"] {
    margin: 0;
    border: none;
    cursor: col-resize;
    background: white;
    background-image: linear-gradient(purple, purple);
    background-size: 2px 100%;
    background-repeat: no-repeat;
    background-position: center;
}

// Layout
.split {
    border: 2px solid purple;
    display: grid;
    grid-template-columns: 34% 1em auto;
    
    aside {
        overflow: hidden;
        padding-right: 1em;
    }
    
    article {
        padding-left: 1em;
    }
}

aside div {
    min-width: 13em;
}
              
            
!

JS

              
                class WindowSplitter {
    constructor (element) {
        this.element = element
        this.target = document.getElementById(element.getAttribute('aria-controls'))
        this.grid = this.target.parentElement
        this.step = 2
        this.value = {
            now: Number(element.getAttribute('aria-valuenow')),
            min: Number(element.getAttribute('aria-valuemin')),
            max: Number(element.getAttribute('aria-valuemax')),
            prev: Number(element.getAttribute('aria-valuenow'))
        }
        this.bindEvents()
        this.dimensions = this.getDimensions()
    }
    
    bindEvents () {
        this.element.addEventListener('keydown', event => this.keyEventHandler (event))
        
        // Ignore for now
        // this.element.addEventListener('drag', event => this.dragEventHandler (event))
        // this.element.addEventListener('dragstart', event => this.dragEventHandler (event))
        // this.element.addEventListener('mousedown', event => this.dragEventHandler(event))
        // this.element.addEventListener('touchstart', event => this.dragEventHandler(event))
    }
    
    getDimensions () {
        return {
            top: this.grid.getBoundingClientRect().top,
            right: this.grid.getBoundingClientRect().right,
            bottom: this.grid.getBoundingClientRect().bottom,
            left: this.grid.getBoundingClientRect().left,
            width: this.grid.getBoundingClientRect().width
        }
    }

    getMousePosition (event) {
        return event.clientX
    }
    
    keyEventHandler (event) {
        event.preventDefault()
        const key = event.key
        
        switch (key) {
            case "ArrowLeft":
            case "ArrowUp":
                this.setSize(this.value.now - this.step)
                break
            case "ArrowRight":
            case "ArrowDown":
                this.setSize(this.value.now + this.step)
                break
            case "Enter":
                this.collapse()
                break
            case "Home":
                this.setSize(this.value.min)
                break
            case "End":
                this.setSize(this.value.max)
                break
            default:
                throw new Error('Something went wrong with the keyboard support')
                break
        }
    }
    
    dragEventHandler (event) {
        // Ignore this for now
        event.preventDefault()
        const dragStartOffset = this.getMousePosition(event)
        console.log('dragStartOffset', dragStartOffset, this.dimensions.width)
        
    }
    
    collapse () {
        if (this.value.now !== 0) {
            this.setSize(0)
        } else {
            this.setSize(this.value.prev)
        }
    }
    
    setSize (size) {
        if (size < this.value.min) {
            size = this.value.min
        } else if (size > this.value.max) {
            size = this.value.max
        }
        this.value.prev = this.value.now
        this.value.now = size
        this.element.setAttribute('aria-valuenow', size)
        this.grid.style.gridTemplateColumns = size + '% 1em auto'
    }
}

Array.from(document.querySelectorAll('[role=separator]'))
    .forEach(element => new WindowSplitter(element))
              
            
!
999px

Console