Extended floating note action in HTML, CSS and vanilla JS
A copy-paste Extended floating note action in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="dcl-floating-action-button-extended" data-dcl-scheme="light">
<h2>Print notes</h2>
<div data-panel class="dcl-floating-action-button-extended-scroller"><ul data-list data-notes><li>Send the sample to the print shop.</li><li>Check the new trim marks.</li><li>Ask for a paper proof.</li></ul><p>Notes for the spring printing run. Add follow-ups here before the next proof.</p><p>Production handoff is scheduled for Thursday.</p>
<div class="dcl-floating-action-button-extended-dock"><button type="button" class="dcl-floating-action-button-extended-primary" data-open aria-expanded="false" aria-controls="dcl-floating-action-button-extended-compose"><span class="dcl-floating-action-button-extended-glyph" aria-hidden="true">+</span> Add note</button></div></div><div data-compose id="dcl-floating-action-button-extended-compose" data-stack data-panel hidden>
<label for="dcl-floating-action-button-extended-note">New note</label><input id="dcl-floating-action-button-extended-note" type="text">
<div data-row><button type="button" class="dcl-floating-action-button-extended-primary" data-save>Add</button><button type="button" data-close>Cancel</button></div></div><p class="dcl-floating-action-button-extended-status" role="status" data-status></p>
<script>
(() => {
const root = document.currentScript.parentElement;
const instance = [...document.getElementsByClassName("dcl-floating-action-button-extended")].indexOf(root);
if (instance > 0) {
for (const node of root.querySelectorAll("[id], [for], [aria-labelledby], [aria-controls], [aria-describedby], a[href], input[name]")) {
for (const key of ["id", "for", "aria-labelledby", "aria-controls", "aria-describedby", "name"]) {
if (node.hasAttribute(key)) node.setAttribute(key, node.getAttribute(key).split(" ").map(value => value + "--" + instance).join(" "));
}
const href = node.getAttribute("href");
if (href && href.startsWith("#")) node.setAttribute("href", href + "--" + instance);
}
}
const scheme = matchMedia("(prefers-color-scheme: dark)");
const applyScheme = () => { root.dataset.dclScheme = scheme.matches ? "dark" : "light"; };
scheme.addEventListener("change", applyScheme);
applyScheme();
const open = root.querySelector("[data-open]");
const compose = root.querySelector("[data-compose]");
const text = compose.querySelector("input");
const status = root.querySelector("[data-status]");
const close = () => { compose.hidden = true; open.setAttribute("aria-expanded", "false"); open.focus(); };
open.addEventListener("click", () => {
if (!compose.hidden) { close(); return; }
compose.hidden = false;
open.setAttribute("aria-expanded", "true");
text.focus();
});
root.querySelector("[data-close]").addEventListener("click", close);
compose.addEventListener("keydown", event => { if (event.key === "Escape") close(); });
root.querySelector("[data-save]").addEventListener("click", () => {
if (!text.value.trim()) { status.textContent = "Enter a note."; text.focus(); return; }
const item = document.createElement("li");
item.textContent = text.value.trim();
root.querySelector("[data-notes]").append(item);
text.value = "";
status.textContent = "Note added.";
close();
});
})();
</script>
</section>
<style>
.dcl-floating-action-button-extended { box-sizing: border-box; max-inline-size: 42rem; padding: clamp(.75rem, 4vw, 1.5rem); border: 1px solid; border-radius: .75rem; font: 1rem/1.5 system-ui, sans-serif; overflow-wrap: anywhere; }
.dcl-floating-action-button-extended *, .dcl-floating-action-button-extended *::before, .dcl-floating-action-button-extended *::after { box-sizing: border-box; }
.dcl-floating-action-button-extended h2, .dcl-floating-action-button-extended h3, .dcl-floating-action-button-extended p, .dcl-floating-action-button-extended ul, .dcl-floating-action-button-extended dl, .dcl-floating-action-button-extended figure { margin: 0; }
.dcl-floating-action-button-extended h2 { font-size: 1.25rem; line-height: 1.25; }
.dcl-floating-action-button-extended h3 { font-size: 1rem; }
.dcl-floating-action-button-extended > * + * { margin-block-start: .75rem; }
.dcl-floating-action-button-extended button, .dcl-floating-action-button-extended summary, .dcl-floating-action-button-extended input, .dcl-floating-action-button-extended select, .dcl-floating-action-button-extended textarea { font: inherit; }
.dcl-floating-action-button-extended button, .dcl-floating-action-button-extended summary { padding: .45rem .7rem; min-block-size: 2.75rem; border: 1px solid; border-radius: .375rem; cursor: pointer; text-align: start; }
.dcl-floating-action-button-extended select, .dcl-floating-action-button-extended input[type="text"], .dcl-floating-action-button-extended textarea { max-inline-size: 100%; padding: .45rem; border: 1px solid; border-radius: .375rem; }
.dcl-floating-action-button-extended button:active { transform: translateY(1px); }
.dcl-floating-action-button-extended button[disabled], .dcl-floating-action-button-extended button[aria-disabled="true"] { cursor: not-allowed; border-style: dashed; transform: none; }
.dcl-floating-action-button-extended button[aria-pressed="true"] { border-style: double; border-width: 3px; }
.dcl-floating-action-button-extended details > summary { inline-size: fit-content; }
.dcl-floating-action-button-extended [data-panel], .dcl-floating-action-button-extended dialog { border: 1px solid; border-radius: .625rem; padding: .8rem; }
.dcl-floating-action-button-extended dialog { max-inline-size: min(calc(100% - 2rem), 28rem); max-block-size: calc(100% - 2rem); }
.dcl-floating-action-button-extended dialog > * + * { margin-block-start: .75rem; }
.dcl-floating-action-button-extended [data-row] { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; min-inline-size: 0; }
.dcl-floating-action-button-extended [data-stack] { display: grid; gap: .6rem; min-inline-size: 0; }
.dcl-floating-action-button-extended [data-list] { list-style: none; padding: 0; display: grid; gap: .55rem; }
.dcl-floating-action-button-extended [data-wide] { flex: 1 1 11rem; min-inline-size: 0; }
.dcl-floating-action-button-extended .dcl-floating-action-button-extended-status { min-block-size: 1.5em; font-weight: 600; }
.dcl-floating-action-button-extended .dcl-floating-action-button-extended-glyph { display: inline-grid; place-items: center; font-size: 1.2em; line-height: 1; }
.dcl-floating-action-button-extended [hidden] { display: none; }
.dcl-floating-action-button-extended { color: #11292f; background-color: #ffffff; color-scheme: light; border-color: #697f84; }
.dcl-floating-action-button-extended a { color: #005c62; }
.dcl-floating-action-button-extended button, .dcl-floating-action-button-extended summary, .dcl-floating-action-button-extended input, .dcl-floating-action-button-extended select, .dcl-floating-action-button-extended textarea { color: #11292f; background-color: #e4edef; border-color: #697f84; }
.dcl-floating-action-button-extended .dcl-floating-action-button-extended-primary, .dcl-floating-action-button-extended button[aria-pressed="true"] { color: #ffffff; background-color: #00535a; }
.dcl-floating-action-button-extended button:hover, .dcl-floating-action-button-extended summary:hover { color: #ffffff; background-color: #00535a; }
.dcl-floating-action-button-extended button[disabled], .dcl-floating-action-button-extended button[aria-disabled="true"] { color: #405a60; background-color: #ffffff; }
.dcl-floating-action-button-extended [data-panel], .dcl-floating-action-button-extended dialog { color: #11292f; background-color: #e4edef; border-color: #697f84; }
.dcl-floating-action-button-extended :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-floating-action-button-extended[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; border-color: #839fa5; }
.dcl-floating-action-button-extended[data-dcl-scheme="dark"] a { color: #8fe1da; }
.dcl-floating-action-button-extended[data-dcl-scheme="dark"] button, .dcl-floating-action-button-extended[data-dcl-scheme="dark"] summary, .dcl-floating-action-button-extended[data-dcl-scheme="dark"] input, .dcl-floating-action-button-extended[data-dcl-scheme="dark"] select, .dcl-floating-action-button-extended[data-dcl-scheme="dark"] textarea { color: #eff8f9; background-color: #1c3c44; border-color: #839fa5; }
.dcl-floating-action-button-extended[data-dcl-scheme="dark"] .dcl-floating-action-button-extended-primary, .dcl-floating-action-button-extended[data-dcl-scheme="dark"] button[aria-pressed="true"] { color: #11292f; background-color: #8fe1da; }
.dcl-floating-action-button-extended[data-dcl-scheme="dark"] button:hover, .dcl-floating-action-button-extended[data-dcl-scheme="dark"] summary:hover { color: #11292f; background-color: #8fe1da; }
.dcl-floating-action-button-extended[data-dcl-scheme="dark"] button[disabled], .dcl-floating-action-button-extended[data-dcl-scheme="dark"] button[aria-disabled="true"] { color: #b0c9ce; background-color: #142f36; }
.dcl-floating-action-button-extended[data-dcl-scheme="dark"] [data-panel], .dcl-floating-action-button-extended[data-dcl-scheme="dark"] dialog { color: #eff8f9; background-color: #1c3c44; border-color: #839fa5; }
.dcl-floating-action-button-extended[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.dcl-floating-action-button-extended .dcl-floating-action-button-extended-scroller { max-block-size: 13rem; overflow: auto; } .dcl-floating-action-button-extended .dcl-floating-action-button-extended-dock { position: sticky; inset-block-end: 0; display: flex; justify-content: end; padding: .45rem; pointer-events: none; } .dcl-floating-action-button-extended .dcl-floating-action-button-extended-dock button { border-radius: 2rem; pointer-events: auto; }
</style>
When to use
Keep the main creation action visible with an icon plus a clear verb.
Avoid
Do not turn the floating position into a second competing primary action.
Accessibility
Use a visible action name, label the field, and return focus to Add note when the edit is cancelled. Light/dark body text: 15.19:1 and 13.07:1, respectively.
Was this useful? Send feedback.