Skip to main content

Link to a section on the same page in Phoenix Code

Click Opening hours at the top of a café menu and the page scrolls down to the café’s weekday and weekend hours. This is an HTML anchor link. Its destination is a spot on the same page, also called a page anchor or Sprungmarke in German. You can try one right here. Jump to the link test in this guide.

You’ll give the link and its destination a matching name. Use the visual controls in Phoenix Pro or edit two HTML tags in Community (free).

1. Open the practice café menu​

  1. Download the Alder Street Café practice project. On Windows, right-click the ZIP and choose Extract All. On macOS, double-click the ZIP. On Linux, use your file manager’s Extract action.
  2. In Phoenix Code, click the folder with a plus at the top left and choose Open Folder…. Select the extracted cafe-hours folder that contains index.html, styles.css, and breakfast.jpg. Use the desktop app on Windows, macOS, or Linux, or the web app in Chrome or Edge. If Chrome asks to view the files in cafe-hours, choose Allow. More about opening a folder.
  3. Double-click index.html in the file list. If the preview is closed, click the lightning bolt on the right. If prompted for this practice folder, choose Trust & Execute Preview.

Look for Alder Street Café, the Opening hours link at the top right, and a photo of mushroom toast. Scroll down in the preview to find the green Opening hours heading below the lunch menu, then scroll back up. The starter link currently points to the top of the page.

The steps below save both changes in index.html. In Chrome, the first save can bring up Save changes to cafe-hours? Choose Save changes to write your edits to the extracted folder.

  1. In the preview toolbar, click the maximize icon to enter Design Mode. Click the pen if it’s gray. An orange pen means Edit Mode is on.
  2. Click Opening hours at the top right of the café menu. A blue toolbar appears beside the selected link. Click its chain icon to open Edit Hyperlink.
  3. In the URL field, replace # with #opening-hours and press Enter. The # tells the browser to look for a destination on this page.

The Opening hours link is selected in Design Mode and the URL field contains #opening-hours.

Name the destination heading​

  1. Scroll down inside the preview. Click the words Opening hours in the green panel. Look for h2 in the blue toolbar. If you see section, click the heading text itself.
  2. Click h2 on the left of the toolbar to open Element Properties. In the ID field, type opening-hours and press Enter. The field has its own # label. Type only the name.
  3. Press Esc to close the panel. Click the Save File icon in the narrow strip to the left of the preview to save index.html. Click the orange pen to turn off editing.

The h2 Element Properties panel shows opening-hours in the ID field beside the green café heading.

Scroll back to the top of the preview and click Opening hours. The same menu should scroll until you can see the green heading, Monday to Friday, 8 am – 4 pm, and Saturday and Sunday, 9 am – 2 pm.

You can also open the saved index.html from your file manager in a browser. Press Tab to focus the link and Enter to follow it. The address now ends in #opening-hours. If the whole menu already fits on your screen, make the window shorter and try again to see the jump.

If clicking the link takes you back to the top, check both values in index.html. The link needs href="#opening-hours" and the heading needs id="opening-hours". Match the spelling, capital letters, and hyphen. Give that ID to just one element on the page, then save and try again.

On your own page, choose a short name for the section you want to link to. For example, a link to #desserts finds the element with id="desserts". To open a separate file such as a contact page, follow Link to another page.