
2026年11月時点で、
概要
選んだのは、
対応状況は、@supports で
網羅してgap、aspect-ratio、clamp()、svh、prefers-reduced-motion のように、
HTML
popover属性でメニューやツールチップを開閉する
popover 属性を
<button type="button" popovertarget="site-menu">メニュー</button>
<nav id="site-menu" popover>
<ul>
<li><a href="/service/">サービス</a></li>
<li><a href="/works/">制作事例</a></li>
</ul>
</nav>
外側のpopover をz-index のdialog を
メニューのように
command・commandfor属性でdialogをJavaScriptなしで開く
ボタンに commandfor(操作するcommand(操作のdialog や popover を
<button type="button" commandfor="contact-dialog" command="show-modal">お問い合わせ</button>
<dialog id="contact-dialog" aria-labelledby="contact-dialog-title">
<h1 id="contact-dialog-title">お問い合わせ</h1>
<p>内容をご入力ください。</p>
<button type="button" commandfor="contact-dialog" command="close">閉じる</button>
</dialog>
command には show-modal・close・request-close・show-popover・hide-popover・toggle-popover を-- からcommand イベントが
モーダルのinert はh1 からaria-labelledby で dialog に
古い
closedbyで外側クリックでも閉じるdialogにする
dialog に closedby="any" を
<dialog id="contact-dialog" closedby="any" aria-labelledby="contact-dialog-title">
…
</dialog>
/* モーダルを開いている間だけ背面のスクロールを止める */
:root {
scrollbar-gutter: stable;
}
:root:has(:modal) {
overflow: hidden;
}
値は any(外側closerequest(Escだけ)、none(どちらでも:root:has(:modal) にbody:has(dialog[open]) だとdialog もbody に overflow: hidden をposition: sticky がscrollbar-gutter: stable は、
閉じるdialog.requestClose() か command="request-close" でclose() とcancel イベントが
const dialog = document.querySelector("#contact-dialog");
const form = dialog.querySelector("form");
dialog.addEventListener("cancel", (event) => {
if (form && new FormData(form).get("message")) {
event.preventDefault();
}
});
closedby は
details要素のname属性で1つだけ開くアコーディオンにする
同じ name 属性をdetails は、
<details name="faq">
<summary>納期はどのくらいですか?</summary>
<p>内容によって変わります。</p>
</details>
<details name="faq">
<summary>修正は何回までできますか?</summary>
<p>工程ごとに決めています。</p>
</details>
開閉のdetails の::details-content を
未対応の
:openで開いている状態にスタイルを当てる
:open は、details・dialog・select・input(日付の
details:open > summary::after {
rotate: 180deg;
}
select:open {
outline: 2px solid var(--focus);
}
details と dialog は[open] 属性でもselect や:open でしか
details と dialog は [open] と
hidden=“until-found”で閉じた中身をページ内検索に載せる
hidden="until-found" を
<button type="button" aria-expanded="false" aria-controls="more">続きを読む</button>
<div id="more" hidden="until-found">
<p>…</p>
</div>
const button = document.querySelector('[aria-controls="more"]');
const more = document.querySelector("#more");
const open = () => {
more.hidden = false;
button.setAttribute("aria-expanded", "true");
};
button.addEventListener("click", open);
// ページ内検索で開いたとき
more.addEventListener("beforematch", open);
未対応のhidden と
search要素で検索フォームを示す
<search> は、
<search>
<form action="/search/">
<label for="q">サイト内を検索</label>
<input id="q" name="q" type="search">
<button>検索</button>
</form>
</search>
role="search" を
fetchpriorityでファーストビューの画像を先に読む
ファーストビューのfetchpriority="high" を
<img src="/img/hero.avif" width="1600" height="900" alt="" fetchpriority="high">
<img src="/img/work-01.avif" width="800" height="600" alt="制作事例のトップページ" loading="lazy">
LCPloading="lazy" をfetchpriority="high" と loading="lazy" を
fetchpriority に
CSS:レイアウトとセレクタ
:has()で子の状態から親にスタイルを当てる
:has() は、
/* 画像があるカードだけ2段にする */
.card:has(> img) {
grid-template-rows: auto 1fr;
}
/* 入力エラーがある項目の枠を赤くする */
.field:has(:user-invalid) {
border-color: var(--error);
}
JavaScriptで
CSS NestingでSassなしに入れ子で書く
ブラウザの
.card {
padding: 1.5rem;
& .card-title {
font-size: 1.25rem;
}
&:hover {
background: var(--surface-hover);
}
@media (width >= 768px) {
padding: 2rem;
}
}
Sassと&__title のように & に
メディアクエリを範囲の記法で書く
メディアクエリのmin-width ではなく
@media (width >= 768px) {
/* 768px以上 */
}
@media (480px <= width < 768px) {
/* 480px以上768px未満 */
}
max-width: 767px と min-width: 768px のように、
Subgridでカード内の高さをそろえる
grid-template-rows: subgrid を
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
gap: 1.5rem;
}
.card {
display: grid;
grid-row: span 3;
grid-template-rows: subgrid;
gap: 0.75rem;
}
カードの
コンテナクエリで置かれた場所の幅に合わせる
コンテナクエリは、
.card-list {
container-type: inline-size;
}
@container (width >= 40rem) {
.card {
grid-template-columns: 12rem 1fr;
}
}
.card-title {
font-size: clamp(1rem, 4cqi, 1.5rem);
}
同じcqi は
スタイルクエリでカスタムプロパティをフラグにする
@container style() は、
.section {
--theme: light;
}
.section.is-dark {
--theme: dark;
}
@container style(--theme: dark) {
.button {
background: #fff;
color: #111;
}
}
サイズのcontainer-type の
Safariではhtml)をbody 以下の
align-contentでブロック要素の中身を縦中央にする
align-content: center が、
.hero {
min-block-size: 60svh;
align-content: center;
}
縦中央にdisplay: flex や grid に
@scopeでコンポーネントの中だけにスタイルを効かせる
@scope は、
@scope (.card) to (.card-body) {
img {
border-radius: 8px;
}
}
.card のimg に.card-body の
未対応の@scope の
Anchor Positioningで要素の位置をほかの要素に合わせる
Anchor Positioningは、
<button type="button" class="help-button" popovertarget="help">?</button>
<div id="help" class="help-tooltip" popover>入力例:090-1234-5678</div>
.help-button {
anchor-name: --help;
}
.help-tooltip {
position-anchor: --help;
position-area: top;
position-try-fallbacks: flip-block;
margin: 0 0 0.5rem;
}
position-area: top でflip-block で
TAKLOGの[popover] の margin を
position-anchor が@supports (anchor-name: --a) が
:user-invalidで入力後にだけエラーを出す
:user-invalid は、
input:user-invalid {
border-color: var(--error);
}
input:user-invalid + .field-error {
display: block;
}
:invalid だと、:user-invalid なら、
field-sizingで入力量に合わせて欄を伸ばす
field-sizing: content をtextarea や input の
textarea {
field-sizing: content;
min-block-size: 4lh;
max-block-size: 16lh;
}
入力にlh(後述)で
未対応のmin-block-size のtextarea に
CSS:色・単位・関数
oklch()とcolor-mix()で色を作る
oklch() は、color-mix() は、
:root {
--brand: oklch(55% 0.15 250);
--brand-soft: color-mix(in oklch, var(--brand) 20%, white);
}
oklch() は
相対カラーで基準の色から濃淡を作る
相対カラーは、
.button {
background: var(--brand);
}
.button:hover {
/* 明るさだけ下げる */
background: oklch(from var(--brand) calc(l - 0.08) c h);
}
.badge {
/* 同じ色で透明度だけ変える */
background: oklch(from var(--brand) l c h / 0.12);
}
ブランドカラーを
未対応の
light-dark()でダークモードの色を1行で書く
light-dark() は、
:root {
color-scheme: light dark;
--bg: light-dark(#fff, #111);
--text: light-dark(#111, #eee);
}
@media (prefers-color-scheme: dark) でcolor-scheme を
contrast-color()で背景に合う文字色を選ぶ
contrast-color() は、
.tag {
background: var(--tag-color);
color: contrast-color(var(--tag-color));
}
管理画面で
lh・cap・rlh単位で文字に合わせて大きさを決める
lh はrlh はcap は
.icon {
/* 英字の大文字と同じ高さのアイコン */
block-size: 1cap;
inline-size: auto;
}
.prose > * + * {
/* 段落の間を1行分あける */
margin-block-start: 1rlh;
}
フォントサイズや
round()で値を一定の刻みにそろえる
round() は、mod() と rem() が
.section {
/* 画面幅に比例させつつ、8px刻みにそろえる */
padding-block: round(nearest, 6vw, 8px);
}
vw でrem() はrem とは
sibling-index()で並び順に応じて遅延をずらす
sibling-index() は、sibling-count() は
.list > li {
transition: opacity 0.4s, translate 0.4s;
transition-delay: calc((sibling-index() - 1) * 80ms);
}
項目を:nth-child() をstyle="--i: 3" を
未対応の
progress()で画面幅に応じた割合を作る
progress() は、
h1 {
/* 画面幅375pxで2rem、1440pxで3.5rem。その間は比例 */
font-size: calc(2rem + 1.5rem * progress(100vw, 375px, 1440px));
}
clamp() でprogress() なら、
未対応のfont-size を
@propertyでカスタムプロパティに型を付けてアニメーションさせる
@property で
@property --angle {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
.ring {
background: conic-gradient(from var(--angle), var(--brand), transparent);
animation: spin 4s linear infinite;
}
@keyframes spin {
to {
--angle: 360deg;
}
}
型の
shape()でclip-pathに曲線を描く
shape() は、clip-path の
.hero {
/* 下端をゆるい弧にする */
clip-path: shape(
from 0% 0%,
line to 100% 0%,
line to 100% 85%,
curve to 0% 85% with 50% 100%,
close
);
}
path() と% や calc() が
未対応の
CSS:アニメーション
@starting-styleでdisplay: noneからの出現を動かす
@starting-style は、transition-behavior: allow-discrete とdisplay の
.menu[popover] {
opacity: 0;
translate: 0 -8px;
transition:
opacity 0.2s,
translate 0.2s,
display 0.2s allow-discrete,
overlay 0.2s allow-discrete;
}
.menu[popover]:popover-open {
opacity: 1;
translate: 0 0;
}
@starting-style {
.menu[popover]:popover-open {
opacity: 0;
translate: 0 -8px;
}
}
popover や dialog の
TAKLOGのdisplay の
linear()でバウンスなどの動きを作る
linear() は、
.toast {
transition: translate 0.6s
linear(0, 0.6 25%, 1.1 50%, 0.95 70%, 1.02 85%, 1);
}
cubic-bezier() では
スクロール連動アニメーションでフェードインをCSSにする
animation-timeline: view() を
@keyframes fade-in {
from {
opacity: 0;
translate: 0 2rem;
}
}
@supports (animation-timeline: view()) {
@media (prefers-reduced-motion: no-preference) {
.fade-in {
animation: fade-in linear both;
animation-timeline: view();
animation-range: entry 0% entry 60%;
}
}
}
IntersectionObserverでanimation-timeline: scroll() で
@supports でopacity: 0 が
View Transitionsでページの切り替えをつなぐ
View Transitionsは、
@view-transition {
navigation: auto;
}
.site-header {
view-transition-name: site-header;
}
移動元とview-transition-name をdocument.startViewTransition() を
ページ間の @view-transition は
CSS:日本語の文字組み
text-wrapで見出しの改行位置を整える
text-wrap: balance は、text-wrap: pretty は、
:where(h1, h2, h3) {
text-wrap: balance;
}
p {
text-wrap: pretty;
}
pretty は
和文のtext-wrap: pretty を
text-autospace・line-break・overflow-wrapで和文を組む
和文の
:root {
line-break: strict;
overflow-wrap: anywhere;
text-autospace: normal;
}
:where(input, textarea, pre, time) {
text-autospace: no-autospace;
}
line-break: strict:句読点や小さい 「ゃ」などが 行頭に 来ないようにします。 overflow-wrap: anywhere:長いURLや 英単語が 枠からは み出すときだけ、 途中で 折り返します。 flexや gridの 中でのは み出しも 防ぎます。 text-autospace: normal:和文と英数字の 間に、 少しだけアキを 入れます。 入力欄、 等幅の pre、日付の timeでは入れないように しています。
これらのtext-autospace はno-autospace 相当にtext-spacing-trim も
word-break: auto-phraseはiPhoneで効かない
word-break: auto-phrase は、
このword-break: auto-phrase を
2026年11月に、<wbr> を<wbr> と
body {
word-break: keep-all;
line-break: strict;
overflow-wrap: break-word;
}
// Astroのビルド後に、HTMLの文章へ <wbr> を入れる処理の中心部分
import { loadDefaultJapaneseParser } from "budoux";
const parser = loadDefaultJapaneseParser();
// テキストノードごとに文節へ分け、<wbr> でつなぐ
const withBreaks = parser.parse(text).join("<wbr>");
word-break: keep-all は、<wbr> と<wbr> がoverflow-wrap: break-word を<wbr> は
Chromeだけで
text-box-trimで文字の上下の余白を詰める
text-box は、
.button {
text-box: trim-both cap alphabetic;
padding: 0.75rem 1.5rem;
}
英字やpadding をcap alphabetic は、
未対応の
text-indent: hangingで注記をぶら下げる
text-indent に hanging を
.note {
text-indent: 1em hanging;
}
「※」でpadding-inline-start とtext-indent を
CSS:スクロールと描画
scrollbar-gutterでスクロールバーの分の横ずれを防ぐ
scrollbar-gutter: stable は、
:root {
scrollbar-gutter: stable;
}
ページの
scrollbar-color・scrollbar-widthでスクロールバーの色と太さを変える
スクロールバーの
.scroll-area {
scrollbar-color: var(--brand) transparent;
scrollbar-width: thin;
}
::-webkit-scrollbar のscrollbar-color は
overscroll-behaviorでスクロールが背面に伝わるのを止める
overscroll-behavior: contain を
dialog,
[popover],
.drawer {
overscroll-behavior-block: contain;
}
モーダルやdialog と [popover] に
content-visibility: autoで長いページの描画を軽くする
content-visibility: auto を
.archive-section {
content-visibility: auto;
contain-intrinsic-size: auto 800px;
}
記事一覧やcontain-intrinsic-size は、
未対応の
backdrop-filterで背面をぼかす
backdrop-filter は、
.site-header {
background: rgb(255 255 255 / 0.7);
backdrop-filter: blur(12px);
}
固定ヘッダーや-webkit- の
未対応の
JavaScript
AbortSignal.timeout()・any()で通信を時間切れで止める
AbortSignal.timeout() は、AbortSignal.any() は、
const controller = new AbortController();
try {
const response = await fetch(`/api/search?q=${encodeURIComponent(query)}`, {
// 新しい検索が始まったら止める・5秒たったら止める
signal: AbortSignal.any([controller.signal, AbortSignal.timeout(5000)]),
});
render(await response.json());
} catch (error) {
if (error.name === "TimeoutError") {
showMessage("時間がかかっています。もう一度お試しください。");
}
}
setTimeout と AbortController をTimeoutError、AbortError に
Promise.withResolvers()でPromiseを外から解決する
Promise.withResolvers() は、
const { promise, resolve } = Promise.withResolvers();
dialog.addEventListener("close", () => resolve(dialog.returnValue), { once: true });
dialog.showModal();
const result = await promise; // 閉じたボタンの value
new Promise((resolve) => { … }) のresolve を
Object.groupBy()・toSorted()で配列を加工する
Object.groupBy() はtoSorted() は、
const byCategory = Object.groupBy(posts, (post) => post.category);
// { seo: [...], form: [...] }
const latest = posts.toSorted((a, b) => b.date - a.date);
// posts の並びは変わらない
reduce で[...posts].sort() でtoReversed()・toSpliced()・with() も
Setのメソッドで集合を比べる
Set に、
const selected = new Set(["seo", "form"]);
const available = new Set(["seo", "form", "ec"]);
selected.isSubsetOf(available); // true
available.difference(selected); // Set {"ec"}
selected.union(new Set(["ga4"])); // Set {"seo", "form", "ga4"}
絞り込み検索でfilter と includes を
Iterator helpersでNodeListを配列にせずに加工する
イテレーターに、map()・filter()・take() などの
const firstThreeTitles = document
.querySelectorAll(".post-card")
.values()
.filter((card) => !card.hidden)
.map((card) => card.querySelector("h3").textContent)
.take(3)
.toArray();
Array.from() や [...nodeList] でtake(3) で
Map.prototype.getOrInsert()で初期値の用意を省く
getOrInsert() は、
const postsByTag = new Map();
for (const post of posts) {
for (const tag of post.tags) {
postsByTag.getOrInsert(tag, []).push(post);
}
}
if (!map.has(key)) map.set(key, []) のgetOrInsertComputed() を
Intl.Segmenterで文字数を正しく数える
Intl.Segmenter は、
const segmenter = new Intl.Segmenter("ja", { granularity: "grapheme" });
const countCharacters = (text) => [...segmenter.segment(text)].length;
countCharacters("👨👩👧"); // 1(text.length だと 8)
入力欄のgranularity: "word" に
RegExp.escape()で検索語を正規表現に入れる
RegExp.escape() は、
const pattern = new RegExp(RegExp.escape(keyword), "gi");
const highlighted = text.replace(pattern, (match) => `<mark>${match}</mark>`);
ユーザーがtext が
URLPatternでURLのパターンを判定する
URLPattern は、
const pattern = new URLPattern({ pathname: "/blog/:slug/" });
const match = pattern.exec(location.href);
match?.pathname.groups.slug; // "seo-basics-what-to-do"
ページごとに
scrollendイベントでスクロールの終わりを受け取る
scrollend は、
const saveScrollPosition = () => {
sessionStorage.setItem("scrollY", String(window.scrollY));
};
if ("onscrollend" in window) {
window.addEventListener("scrollend", saveScrollPosition);
} else {
let timer;
window.addEventListener("scroll", () => {
clearTimeout(timer);
timer = setTimeout(saveScrollPosition, 150);
});
}
scroll イベントと
ariaNotify()で読み上げに知らせる
ariaNotify() は、
const announce = (message) => {
if ("ariaNotify" in document) {
document.ariaNotify(message);
} else {
liveRegion.textContent = message;
}
};
announce("カートに追加しました");
これまでは、aria-live のariaNotify() なら、
JSONをimportで読み込む
with { type: "json" } を
import settings from "./settings.json" with { type: "json" };
console.log(settings.breakpoints);
fetch() して response.json() する
AIに書かせるときはModern Web Guidanceを入れる
コーディングエージェントに
READMEに
- 約250の
Web機能 (CSSと レイアウトが 140、 HTMLと DOMが 36、 JavaScriptと APIが 74)と、 203の 実践的な 使い方の ガイドを 収録しています。 - Baselineの
対応状況の データを 参照し、 プロジェクトが 目標に する 対応範囲に 合わせて 提案を 変えます。 目標の 初期値は 「Baseline Widely available」です。 - 古い
ブラウザが 無視しても 困らない 機能は そのまま 使い、 重要な 動作には 軽いフォールバックを 付ける、と いう 方針です。 この 記事の 選び方と 同じ 考え方です。 - 実験中の
機能や Origin Trialの 機能は、 開発者が 許可するまで エージェントが 採用しないようになっています。 npx modern-web-guidance@latest installで、使っている エージェントに 入れられます。 インストールせずに、 古い 書き方を 探す legacy-scanなどのコマンドを 試すこともできます。
GoogleのModern Web Guidance 101(コードラボ)では、AGENTS.md にfetchpriority="high" と loading="lazy" をcontent-visibility: auto を
案件のAGENTS.md に
まだ見送るもの
次の
if()関数、calc-size()とinterpolate-size(アコーディオンの高さの アニメーションは、 上で 紹介した 記事のように フォールバック付きなら 使えます) appearance: base-selectによる カスタマイズ可能な select(Firefoxは未対応) - スクロール状態の
コンテナクエリ ( scroll-state()) text-spacing-trim、word-break: auto-phrase(どちらもChrome系だけ)
まとめ
- 主要ブラウザが
そろって 対応した 機能は、 @supportsの逃げ道を 添えれば 案件に 入れられます。 一部の ブラウザだけの 機能は、 効かなくても 壊れない 所に 足します。 - モーダル・メニュー・ツールチップ・アコーディオンは、
dialog・popover・command・detailsとAnchor Positioningで、 JavaScriptを ほとんど 書かずに 作れます。 - Nesting・
:has()・範囲の記法・ コンテナクエリは 広く 対応に なり、 Sassの 変換や JavaScriptの 判定なしで 書けます。 - 和文の
文節改行は、 word-break: auto-phraseがiPhoneで 効きません。 必要なら ビルド時に <wbr>を入れ、 iPhoneで 確かめます。 - AIに
書かせる ときは、 対応範囲を AGENTS.mdに日付で 書き、 Modern Web Guidanceを 入れます。
新しい