Main Content


Create hyperlink component

Since R2021a


hlink = uihyperlink creates a hyperlink component in a new figure window and returns the Hyperlink object. MATLAB® calls the uifigure function to create the figure.


hlink = uihyperlink(parent) creates the hyperlink in the specified parent container. The parent can be a figure created using the uifigure function or one of its child containers.


hlink = uihyperlink(___,Name,Value) specifies hyperlink properties using one or more name-value arguments. For example, you can specify the display text and URL of the hyperlink using the Text and URL name-value arguments. Use this option with any of the input argument combinations in the previous syntaxes.


collapse all

Create a hyperlink component. Change the display text to 'MathWorks' and set it to link to the MathWorks® home page.

fig = uifigure;
hlink = uihyperlink(fig);
hlink.Text = "MathWorks";
hlink.URL = "";

Hyperlink with text "MathWorks"

When the app user clicks on the link, the MathWorks home page opens in a new browser tab.

Create a default hyperlink component.

fig = uifigure;
hlink = uihyperlink(fig);

Change the URL to link to the MathWorks home page. Add a tooltip that shows the URL when the app user hovers their pointer over the hyperlink.

hlink.URL = "";
hlink.Tooltip = hlink.URL;

Hyperlink with text "Hyperlink". A mouse pointer is on the hyperlink, and the tooltip shows the URL of the MathWorks home page.

Create a default hyperlink.

fig = uifigure;
hlink = uihyperlink(fig);

Change the link text and URL.

hlink.Text = "MathWorks home page";
hlink.URL = ""

Hyperlink with clipped text. Only the word "MathWorks" and part of the "h" character are visible.

The link text is clipped because the current size is too small for the new text.

Determine the current link size by getting the third and fourth elements of the Position property value.

size = hlink.Position(3:4)
size =

    70    22

Change the size to accommodate the new text.

hlink.Position(3:4) = [150 22];

Hyperlink with text "MathWorks home page"

To make a link open a file on the app user's system when clicked, use the file:/// URL scheme.

Create an HTML file from an example program file using publish. Specify the name of a program file in the current folder so that the code can run during the publishing process.

htmlFile = publish("fourier_demo2.m");

Create a hyperlink component. Use the file:/// URL scheme to enable MATLAB to open the file.

fig = uifigure;
hlink = uihyperlink(fig);
hlink.URL = "file:///" + htmlFile;

Clicking on the hyperlink opens the file for viewing in the system browser.

To make a link send an email when clicked, use the mailto: URL scheme.

Create a default hyperlink component.

fig = uifigure;
hlink = uihyperlink(fig);

To run this example, replace the value for email with a valid email address.

email = 'myaddress@provider.ext';
hlink.URL = ['mailto:' email];

When the app user clicks on the link, the default mail client opens a new email with the destination field pre-populated with email.

Create a hyperlink with a custom effect: it creates a plot as well as opening a URL when the app user clicks it. To do this, create a set of UI axes and a HyperlinkClickedFcn callback that creates a plot in these axes.

Create a file named hyperlinkPlot.m on your MATLAB path that contains the following code. This code creates a window containing a hyperlink and a set of UI axes. When the app user clicks the link, first the app user's browser loads the MATLAB product page, then the HyperlinkClickedFcn callback plots some data.

function hyperlinkPlot
% Create a figure window and UI axes
fig = uifigure;
ax = uiaxes(fig);

% Create a hyperlink
hlink = uihyperlink(fig,...
    "Position",[200 350 70 22], ...
    "Text","MATLAB", ...
    "URL","", ...
    "HyperlinkClickedFcn",@(hlink,event) plotHyperlinkClicked(hlink,ax));

% Create the function for the HyperlinkClickedFcn callback
function plotHyperlinkClicked(hlink,ax)
    L = 160*membrane(1,100);
    s = surf(ax,L);
    s.EdgeColor = 'none';

Run hyperlinkPlot, then click the link. MATLAB opens the URL, then plots the data.

Hyperlink with the text "MATLAB" above a surface plot

Input Arguments

collapse all

Parent container, specified as a Figure object created using the uifigure function or one of its child containers: Tab, Panel, ButtonGroup, or GridLayout. If you do not specify a parent container, MATLAB calls the uifigure function to create a new Figure object that serves as the parent container.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: uihyperlink('Text','Click me') specifies the hyperlink displays the text Click me.


The properties listed here are a subset of the available properties. For the full list, see Hyperlink Properties.

Hyperlink display text, specified as a character vector, cell array of character vectors, string scalar, string array, or 1-D categorical array. Use a cell array of character vectors or a string array to specify multiple lines of text.

Example: 'Click here'

Example: {'Click' 'Here'}

Hyperlink URL, specified as a character vector or string scalar. When the hyperlink is clicked, the web address opens in a new browser tab. If the user is running the app in a browser via MATLAB Online™ or as a web app, the new tab opens in the current browser. Otherwise, the new tab opens in the default browser on the user's system.

Hyperlink clicked callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes after the URL opens when the user clicks the hyperlink.

This callback function can access specific information about the user's interaction with the hyperlink. MATLAB passes this information in a HyperlinkClickedData object as the second argument to your callback function. In App Designer, the argument is called event. You can query the object properties using dot notation. For example, event.Source returns the Hyperlink object. The HyperlinkClickedData is not available to callback functions specified as character vectors.

The following table lists the properties of the HyperlinkClickedData object.

SourceComponent that executes the callback

For more information about writing callbacks, see Callbacks in App Designer.

Hyperlink location and size, relative to the parent, specified as the vector [left bottom width height]. This table describes each element in the vector.

leftDistance from the inner left edge of the parent container to the outer left edge of the label
bottomDistance from the inner bottom edge of the parent container to the outer bottom edge of the label
widthDistance between the right and left outer edges of the label
heightDistance between the top and bottom outer edges of the label

The Position values are relative to the drawable area of the parent container. The drawable area is the area inside the borders of the container and does not include the area occupied by decorations such as a menu bar or title.

All measurements are in pixel units.

Example: [100 100 100 20]

Version History

Introduced in R2021a

See Also