The backslash sits above or next to the Enter key on US keyboards, and to the left of the Z key on most UK keyboards. On both layouts the vertical bar | is normally the shifted version of that same key, so hold Shift and press it. Or copy either character:
If neither character appears where you expect it, the layout your computer is using does not match the printing on your keycaps. The on-screen keyboard settles that question in seconds, and the fix is below.
Where the backslash key lives
| Layout | Typical position of the \ key |
|---|---|
| US (Windows and Mac) | Above or next to Enter, at the right of the keyboard |
| UK (most keyboards) | To the left of the Z key, on the bottom letter row |
| Other layouts | Varies — check the on-screen keyboard or Keyboard Viewer |
That relocation is the single biggest source of confusion. A UK keyboard has an extra key squeezed in beside the left Shift, and that is where the backslash went. Because US and UK keyboards have different key counts, plugging a UK keyboard into a machine set to the US layout leaves that extra key producing something unexpected, and the backslash apparently missing.
The vertical bar is almost always the shifted character on the same key on both layouts. If pressing Shift with it gives you something else, your layout is not what you think it is — open the on-screen keyboard as described next.
See your real layout on Windows
Press Windows + R, type osk and press Enter to open the On-Screen Keyboard; searching the Start menu for "On-Screen Keyboard" works too, and on current Windows versions Windows + Ctrl + O opens it. Click its Shift key and look for \ and |. Whatever key they appear on is the key to press on your physical keyboard, no matter what the keycap says.
You can also click the characters directly in the On-Screen Keyboard, which is the quickest workaround when a physical key has failed. If you have more than one layout installed, Windows + Space cycles through them; layouts are added and removed under Settings > Time & language > Language & region, in each language’s options.
See your real layout on a Mac
Open System Settings > Keyboard, find the Text Input or Input Sources section, and turn on the option to show the Input menu in the menu bar. From that menu choose Show Keyboard Viewer. The Keyboard Viewer draws your live layout and updates as you hold modifier keys, so hold Shift to find the vertical bar. The same Input menu switches between installed layouts. Typing special characters on a Mac covers the Character Viewer and other Mac input tools.
Neither character needs an Alt code
Backslash is U+005C REVERSE SOLIDUS and the vertical bar is U+007C VERTICAL LINE. Both are original ASCII characters, present in essentially every font, encoding and keyboard layout ever made, so there is no Alt code worth memorizing for either. Alt codes exist to reach characters that are genuinely absent from your layout, such as £, € or ° — the Alt code finder is the place to look for those, and how Alt codes work explains why they need a numeric keypad.
When the key itself is unreachable — a broken switch, a stripped-down laptop, a remote session with a wrong layout — these all work:
- Windows emoji & symbol panel: Windows + . (or Windows + ;), then the Symbols tab.
- Character Map: search the Start menu for Character Map, or run
charmap. - Mac Character Viewer: Control + Command + Space, then search for reverse solidus or vertical line — the Unicode names, not the everyday ones.
- Microsoft Word: type
005Cthen press Alt + X for a backslash, or007Cthen Alt + X for a vertical bar. - Excel:
=UNICHAR(92)and=UNICHAR(124). - Google Docs: Insert > Special characters, then search by Unicode name.
- Copy and paste: take it from the reverse solidus reference page or the symbol search.
Backslash or forward slash?
They are different characters with almost no overlap in use, and picking the wrong one is the most common mistake in this area.
Backslash \ |
Forward slash / |
|
|---|---|---|
| Unicode | U+005C REVERSE SOLIDUS | U+002F SOLIDUS |
| HTML | \ or \ |
/ or / |
| Leans | Top-left to bottom-right | Bottom-left to top-right |
| File paths | Windows: C:\Users\Documents |
macOS, Linux: /Users/Documents |
| Web addresses | Never used | Always used: https://example.com/page/ |
A useful memory aid: the forward slash leans forward in the direction you read, and it is the one used in URLs and dates. The backslash leans back and belongs to Windows file paths and programming escape sequences. A web address never contains a backslash — if you see one in what claims to be a link, treat it with suspicion.
In code, the backslash is the escape character in most languages: \n is a newline, \t a tab, and \\ is how you write a single literal backslash. That is why Windows paths inside source code often appear with doubled backslashes. It also escapes special characters in regular expressions, and in Markdown it prevents the next character from being treated as formatting.
What the vertical bar is used for
The vertical bar, usually called the pipe, has a heavier workload than its appearance suggests. On the command line it pipes one command’s output into the next, as in ls | grep report. In regular expressions it means "or". In many programming languages a single | is a bitwise OR and a doubled || is a logical OR. In Markdown it separates table columns. In mathematical notation it marks absolute value and set-builder conditions, which is why our database files it under the math category rather than with the punctuation.
Do not confuse it with the broken bar ¦, U+00A6, which is drawn with a gap in the middle. Some older keyboards printed a broken bar on the keycap while the key actually produced a solid vertical line, which is a historical quirk rather than a fault. The broken bar has no syntactic meaning in shells or programming languages, so pasting one where a pipe belongs produces an error. It does have a Windows Alt code, Alt + 0166, if you ever need the character itself.
When the key still will not work
- You get # or ` instead. Layout mismatch. Press Windows + Space, or switch input source on a Mac, then try again.
- The key does nothing in a remote session. Remote desktop clients, virtual machines and browser terminals apply their own layout. Set the layout inside the session, not just on the host.
- A compact or 60% keyboard has no visible key. Small mechanical keyboards move
\onto a function layer. Check the keyboard’s layer chart or its configuration software. - A word processor changes what you typed. AutoCorrect and substitution features can replace characters as you type. In Google Docs, Tools > Preferences > Substitutions can be switched off; Word’s equivalents are under AutoCorrect Options.
- It types twice or not at all. Before blaming the layout, test the key in the On-Screen Keyboard, which highlights keys as they are pressed and distinguishes a hardware fault from a software one.
Related symbols
Characters that get mistaken for these two include the broken bar ¦, the fraction slash ⁄ used in typeset fractions like ½, and the division sign ÷, which is the correct character for arithmetic where people often type a forward slash. The number sign # is worth knowing too, because it is what a mismatched layout most often produces in place of a backslash. Browse the punctuation category for the rest of the keyboard’s workhorse characters, and see Unicode vs. ASCII for why these old characters work everywhere.
Frequently asked questions
Where is the backslash key on a UK keyboard?
On most UK keyboards it is the extra key immediately to the left of Z on the bottom letter row, not near Enter as on US keyboards. If it is not there, your machine is probably set to a different layout than the keyboard was built for — open the On-Screen Keyboard to see the layout actually in use.
Is there an Alt code for the backslash?
None that you need. The backslash is a standard ASCII character on every keyboard layout, so the task is to find its key rather than to enter a code. If the key is broken, use the Windows emoji and symbol panel with Windows + ., or copy the character from a reference page.
What is the difference between \ and /?
The backslash, U+005C, leans left and is used for Windows file paths and escape sequences in code. The forward slash, U+002F, leans right and is used in web addresses, macOS and Linux paths, dates and fractions. They are not interchangeable in any context.
How do I type the pipe character?
Hold Shift and press the backslash key; on both US and UK layouts the vertical bar is normally the shifted character on that key. If it produces something else, check the on-screen keyboard or Keyboard Viewer for your real layout.
Why does my keyboard show a broken bar on the key?
Some keyboards print ¦ even though the key produces a solid vertical line |. It is a leftover from older character sets, and the character you actually get is U+007C VERTICAL LINE, which is what shells and programming languages expect.