TipsBlocks Web Technique Library

PRACTICAL WEB TIP

← ライブラリへ戻る

マージンノート — ページトップボタン

ページ余白に置く短い罫線とセリフ体の文字。編集記事になじむ左下配置のページトップリンク。

デザインプレビュー

まず形と大きさを確認。実際の動作は下のLive Demoで試せます。

造形とホバー
サイトでの実寸イメージ

Live Demo

枠内の「動作を試す」を押すか、枠の中をスクロールしてください。右下にボタンが現れ、クリックすると先頭へ戻ります。

Source Code

必要なコードをコピーして実装に利用できます。

HTML
<!-- TB-2050 / Margin Note | paste before closing body -->
<button class="backtop tb-btt-button w2050" type="button" aria-label="Back to top"><span class="w50bar"></span><span class="w50arrow">↗</span><span class="w50copy">To the top</span></button>
CSS
/* TB-2050 / Margin Note */
.backtop{box-sizing:border-box;position:fixed;z-index:50;cursor:pointer;opacity:0;visibility:hidden;pointer-events:none;transform:translateY(12px);text-align:center;transition:opacity .24s, transform .28s, visibility .24s}.backtop.is-visible{opacity:1;visibility:visible;pointer-events:auto;transform:translateY(0)}.backtop.w2055.is-visible{transform:translate(-50%,0)}.backtop:focus-visible{outline:3px solid #e7ab4c;outline-offset:4px}
.w2050{left:28px;bottom:29px;min-width:118px;height:45px;display:flex;align-items:center;gap:11px;padding:0 7px;background:transparent;color:#352e29;border:0;filter:drop-shadow(0 1px 1px #fff)}.w50bar{width:26px;height:1px;background:currentColor;transition:width .34s}.w50arrow{font:400 18px/1 Georgia,serif;transform:rotate(-45deg);display:inline-block}.w50copy{font:italic 15px Georgia,serif;white-space:nowrap}.w2050:hover .w50bar{width:45px}.w2050:hover .w50arrow{transform:rotate(-45deg) translate(2px,-2px)}
@media(prefers-reduced-motion:reduce){*,*:before,*:after{transition-duration:.01ms!important;animation-duration:.01ms!important}}
/* POLISH PASS 2026-10-18: alignment, tactile size, emphasis & individual character */
.backtop{isolation:isolate;-webkit-tap-highlight-color:transparent;}
.backtop:focus-visible{outline:3px solid #f0af42;outline-offset:4px;}
@media(prefers-reduced-motion:reduce){.backtop,.backtop *{transition-duration:.01ms!important;animation-duration:.01ms!important}}

.w2050{left:clamp(22px,4vw,70px);bottom:clamp(29px,5vh,65px);min-width:142px;height:51px;padding:0 10px;gap:14px;color:#302d2a;background:#f8f4eddc;border-bottom:1px solid #a59989;filter:none;text-align:left;}
.w2050 .w50copy{white-space:nowrap;}
.w2050:hover{background:#e7ded1;transform:translateY(-3px)}
@media(max-width:650px){.w2050{left:18px;bottom:24px;min-width:128px;height:48px}}
JavaScript
(()=>{'use strict';const button=document.querySelector('.backtop');if(!button)return;const footerOnly=button.classList.contains('footer-backtop');const reduced=matchMedia('(prefers-reduced-motion: reduce)');let scheduled=false;function update(){scheduled=false;if(footerOnly)return;const shown=window.scrollY>160;button.classList.toggle('is-visible',shown);button.classList.toggle('is-hidden',!shown);button.tabIndex=shown?0:-1;button.setAttribute('aria-hidden',String(!shown));if(button.classList.contains('w2056')){const max=Math.max(1,document.documentElement.scrollHeight-innerHeight);button.style.setProperty('--progress',(Math.round(Math.min(100,scrollY/max*100)))+'%');}}function onScroll(){if(!scheduled){scheduled=true;requestAnimationFrame(update)}}button.addEventListener('click',()=>window.scrollTo({top:0,behavior:reduced.matches?'instant':'smooth'}));addEventListener('scroll',onScroll,{passive:true});addEventListener('resize',onScroll,{passive:true});update();})();

How to Use

HTMLのボタンをbody末尾付近へ設置し、CSSを読み込んでください。JavaScriptもdeferで読み込みます。実ページでスクロール後の表示・先頭復帰・スマートフォンでの位置を確認してください。

Use Case

雑誌風メディア、エディトリアル、長文記事。

Technical Notes

ホバー非対応端末でも主要操作ができるようにし、キーボードフォーカス時の表示と動き軽減設定を確認してください。

Mobile:端末幅ごとにボタンの位置とタップ領域を確認してください。

Browser:モダンブラウザ向け。実際のページでのレイアウトを検証してください。

Reduced Motion:prefers-reduced-motion 設定によりアニメーションを抑制します。