The copy button obstructs the text selection and code copying within the code blocks in mobile view.
Describe the bug
When trying to select and copy text, the copy button positioned above the text prevents full selection.
Reproduction
Please watch this video for a detailed look.
https://github.com/user-attachments/assets/b6a5914f-9d82-4b0c-a4e0-c97c67f44afd
Expected behavior
Perhaps the copy button should be positioned elsewhere in the mobile view.
System Info
Originally reported on iOS 26; the same behaviour is present on iOS 27 (and on desktop browsers when the window is narrowed to a phone-sized viewport), so it looks device-independent and depends on the code block width instead.
System:
OS: macOS 27.0
CPU: (10) arm64 Apple M4
Memory: 77.42 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 26.4.0 - /usr/local/bin/node
npm: 12.0.2 - /usr/local/bin/npm
pnpm: 11.11.0 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 153.0.8010.53
Safari: 27.0
npmPackages:
vitepress: ^2.0.0-alpha.20 => 2.0.0-alpha.20Additional context
Not device-specific — it reproduces in desktop browsers at a narrow viewport.
Measured at a 390px-wide viewport (macOS 27, 2x DPR) on vitepress.dev/guide/markdown:
| Engine | copy button | style at the button | elementFromPoint() at its centre |
drag starting inside the button | drag starting on the code text |
|---|---|---|---|---|---|
| Chromium 152 | 40x40 at the top-right (top: .75rem, inset-inline-end: .75rem) |
opacity: 0, pointer-events: auto, z-index: 3 |
BUTTON.copy |
selects 0 characters | selects 24 characters |
| WebKit 26.6 | same | same | BUTTON.copy |
selects 0 characters | selects 24 characters |
Cause: the button is hidden with opacity: 0 only, which keeps it in the hit-testing layer, so the top-right 40x40 area of every code block swallows pointer and touch events. Visibility is driven by :hover, so on touch devices the button also appears in the middle of a selection (sticky hover).
Direction: keep the button in place and make it step out of the way while text is being selected. The overlays (button.copy, span.lang) are now rendered after the <pre> — they are absolutely positioned, so nothing moves visually, but a selection that continues into the code can no longer wrap around them (WebKit used to paint a blue box for each). The hidden button also gets pointer-events: none, visibility: hidden and user-select: none, while :hover / :focus / :focus-within restore visibility: visible + pointer-events: auto, so it stays clickable and keyboard-reachable. While a block contains a selection, the button and the language label step aside (a .selecting class toggled from selectionchange), and the button keeps its original 0.25s opacity transition.
Measured in Chromium 152 and WebKit 26.6 at a 390px viewport: the overlays no longer appear in the selection rects, the pixel diff inside the button's area drops from 28.7% to 0%, drag-selection works again, the copy button still works (click → Copied), and pre padding stays 20px / 0.
Separate observation (not addressed by this change): on iOS Safari, long-pressing the first characters of a code block places the selection at the end of the previous line (a constant one-line upward offset). It reproduces on a plain <pre><code> page with no VitePress markup (same content, with/without tabindex, with/without a scroll container, with zero top padding), so it looks like a WebKit behaviour rather than a theme issue.
Validations
- Check if you're on the latest VitePress version.
- Follow our Code of Conduct
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Source: vuejs/vitepress